Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8944

groovyc: invalid constant pool entry

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Duplicate
    • Affects Version/s: 2.4.16
    • Fix Version/s: None
    • Component/s: Compiler
    • Labels:
      None

      Description

      Updated our projects to Groovy 2.4.16 today and ran into a problem with one of our test helpers.  This functional interface performs a similar function to GroovyAssert.shouldFail. Whenever it is referenced from statically compiled Groovy, there is a bytecode error for the reference to java.lang.Throwable. This error is not present in Groovy 2.4.15, which should help isolate the cause.

      java.lang.VerifyError: Illegal type at constant pool entry 53 in class CatchableTest
      Exception Details:
        Location:
          CatchableTest.testTryCatch()V @14: invokestatic
        Reason:
          Constant pool index 53 is invalid
        Bytecode:
          0x0000000: bb00 1e59 2a2a b700 21ba 002f 0000 b800
          0x0000010: 354c 2b57 1237 2bb6 003b b800 4001 57b1
          0x0000020:                                        
      
      	at java.lang.Class.getDeclaredMethods0(Native Method)
      	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
      	at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
      	at java.lang.Class.getMethod0(Class.java:3018)
      	at java.lang.Class.getMethod(Class.java:1784)
      
      import org.junit.Assert
      import org.junit.Test
      
      @groovy.transform.CompileStatic
      final class CatchableTest {
          @Test
          void testTryCatch() {
              Throwable t = Catchable.tryCatch {
                  println 'throwing new exception'
                  throw new IllegalStateException()
              }
              Assert.assertEquals(IllegalStateException, t.getClass())
          }
      }
      
      /**
       * <code>
       * Throwable t = Catchable.tryCatch(() -> obj.method(params));<br>
       * assertThat(t).isInstanceOf(SomeException.class).hasMessage("whatevs");
       * </code>
       * <p>
       * Adapted from http://www.codeaffine.com/2014/07/28/clean-junit-throwable-tests-with-java-8-lambdas/
       */
      @FunctionalInterface
      public interface Catchable {
          void op() throws Throwable;
      
          static Throwable tryCatch(final Catchable thrower) {
              try {
                  thrower.op();
                  return null;
              } catch (final Throwable thrown) {
                  return thrown;
              }
          }
      }
      

        Attachments

          Activity

            People

            • Assignee:
              emilles Eric Milles
              Reporter:
              emilles Eric Milles
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: