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

VerifyError when using generic container in closure

    XMLWordPrintableJSON

Details

    Description

      The following code produces a VerifyError. It appears to this amateur eye that the code in the closure actually performs an invokedynamic on the nested method reference and then calls the Iterable's forEach, when I would expect it to push a reference to the method handle somehow and then let that be passed to forEach.

      @Grab('org.apache.pdfbox:pdfbox:2.0.28')
      import org.apache.pdfbox.pdmodel.*
      @Grab('io.vavr:vavr:0.10.4')
      import io.vavr.control.Try
      @CompileStatic
      @POJO
      class Bug {
          public static void main(String... args) {
              PDDocument doc = new PDDocument()
              extraPages().forEach {
                  it.forEach(doc::addPage)
              }
          }
          static Try<Iterable<PDPage>> extraPages() {
              return Try.success([null]) // value present only to cause the iteration to proceed; NPE is the expected outcome here
          }
      }
      
      java.lang.VerifyError: Bad type on operand stack
      Exception Details:
        Location:
          Bug$_main_closure1.doCall(Ljava/lang/Object;)Ljava/lang/Void; @11: invokedynamic
        Reason:
          Type 'java/lang/Object' (current frame, stack[1]) is not assignable to 'org/apache/pdfbox/pdmodel/PDDocument'
        Current Frame:
          bci: @11
          flags: { }
          locals: { 'Bug$_main_closure1', 'java/lang/Object' }
          stack: { 'java/lang/Iterable', 'java/lang/Object' }
        Bytecode:
          0000000: 2bc0 0024 2ab4 001c b600 2aba 003f 0000
          0000010: b900 4302 0001 ba00 5000 00b0          
      
      	at Bug.main(Bug.groovy:16)
      
        public java.lang.Void doCall(java.lang.Object);
          descriptor: (Ljava/lang/Object;)Ljava/lang/Void;
          flags: (0x0001) ACC_PUBLIC
          Code:
            stack=2, locals=2, args_size=2
               0: aload_1
               1: checkcast     #36                 // class java/lang/Iterable
               4: aload_0
               5: getfield      #28                 // Field doc:Lgroovy/lang/Reference;
               8: invokevirtual #42                 // Method groovy/lang/Reference.get:()Ljava/lang/Object;
              11: invokedynamic #63,  0             // InvokeDynamic #0:accept:(Lorg/apache/pdfbox/pdmodel/PDDocument;)Ljava/util/function/Consumer;
              16: invokeinterface #67,  2           // InterfaceMethod java/lang/Iterable.forEach:(Ljava/util/function/Consumer;)V
              21: aconst_null
              22: invokedynamic #80,  0             // InvokeDynamic #1:cast:(Ljava/lang/Object;)Ljava/lang/Void;
              27: areturn
            LineNumberTable:
              line 17: 0
            LocalVariableTable:
              Start  Length  Slot  Name   Signature
                  0      28     0  this   LBug$_main_closure1;
                  0      28     1    it   Ljava/lang/Object;
          MethodParameters:
            Name                           Flags
            it
      

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              chrylis Christopher Smith
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: