[ 
https://issues.apache.org/jira/browse/GROOVY-11068?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Christopher Smith updated GROOVY-11068:
---------------------------------------
    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}}.

{code}
@Grapes([
  @Grab('org.apache.pdfbox:pdfbox:2.0.28'),
  @Grab('io.vavr:vavr:0.10.3')
])
@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
    }
}
{code}

{code}
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)
{code}

{code}
  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
{code}

  was:
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}}.

{code}
@Grapes([
  @Grab('org.apache.pdfbox:pdfbox:2.0.28'),
  @Grab('io.vavr:vavr:0.10.3')
])
@CompileStatic
@POJO
class Bug {

    public static void main(String... args) {
        PDDocument doc = new PDDocument()//PDDocument.load(new 
File('/tmp/sample.pdf'))
        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
    }
}
{code}

{code}
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)
{code}

{code}
  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
{code}


> VerifyError when using generic container in closure
> ---------------------------------------------------
>
>                 Key: GROOVY-11068
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11068
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 4.0.12
>            Reporter: Christopher Smith
>            Priority: Major
>
> 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}}.
> {code}
> @Grapes([
>   @Grab('org.apache.pdfbox:pdfbox:2.0.28'),
>   @Grab('io.vavr:vavr:0.10.3')
> ])
> @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
>     }
> }
> {code}
> {code}
> 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)
> {code}
> {code}
>   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
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to