You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (JIRA)" <ji...@apache.org> on 2019/06/09 21:35:00 UTC

[jira] [Commented] (GROOVY-6809) VerifyError With Inner Class

    [ https://issues.apache.org/jira/browse/GROOVY-6809?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16859579#comment-16859579 ] 

Eric Milles commented on GROOVY-6809:
-------------------------------------

The AIC examples have a different bytecode sequence in Java vs Groovy.  For this Java example:
{code:java}
public class Runner {
  public static void main(String[] args) {
    new Runner();
  }
  public Runner() {
    this(new Runnable() {
      @Override public void run() {
        System.out.println("ran");
      }
    });
  }
  public Runner(Runnable action) {
    action.run();
  }
}
{code}
The no-arg constructor only delegates to another constructor after creating a new AIC.
{code}
  // Method descriptor #15 ()V
  // Stack: 3, Locals: 1
  public Runner();
     0  aload_0 [this]
     1  new Runner$1 [3]
     4  dup
     5  invokespecial Runner$1() [4]
     8  invokespecial Runner(java.lang.Runnable) [5]
    11  return
      Line numbers:
        [pc: 0, line: 6]
        [pc: 11, line: 11]
{code}

The groovyc version of the same looks like this:
{code}
  // Method descriptor #15 ()V
  // Stack: 4, Locals: 1
  public Runner();
     0  aload_0 [this]
     1  new Runner$1 [17]
     4  dup
     5  aload_0 [this]
     6  invokespecial Runner$1(Runner) [20]
     9  invokespecial Runner(java.lang.Runnable) [23]
    12  return
      Line numbers:
        [pc: 0, line: 13]
        [pc: 12, line: 18]
      Local variable table:
        [pc: 0, pc: 12] local: this index: 0 type: Runner
{code}

Looks like groovyc created a constructor "Runner$1(Runner)" and javac created "Runner$1()", requiring no this reference passed during construction.

> VerifyError With Inner Class 
> -----------------------------
>
>                 Key: GROOVY-6809
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6809
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 2.3.0, 2.4.0-beta-3
>            Reporter: Jeff Brown
>            Priority: Major
>
> The following code compiles but throws a VerifyError at runtime:
> {code:title=Test.groovy|borderStyle=solid}
> class Test {
>     static void main(String[] args) {
>         def a = new A()
>     }
>     static class A {
>         A() {
>             def b = new B()
>         }
>         void sayA() { println 'saying A' }
>         class B extends A {
>             public B() {
>                 super(A.this)
>                 sayA()
>             }
>         }
>     }
> }
> {code}
> I didn't go back through versions but I tested with 2.3.0 and that shows the problem.
> {noformat}
> Caught: java.lang.VerifyError: (class: Test$A$B, method: <init> signature: (LTest$A;)V) Expecting to find object/array on stack
> java.lang.VerifyError: (class: Test$A$B, method: <init> signature: (LTest$A;)V) Expecting to find object/array on stack
> 	at Test$A.<init>(Test.groovy:9)
> 	at Test.main(Test.groovy:4)
> {noformat}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)