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

Calling back into java base class method inside an if statement causes java.lang.VerifyError: Inconsistent stack height 1 != 0

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.0-RC-2
    • 1.1-beta-1
    • class generator
    • None
    • Windows XP, SUN JVM 1.4.2_12

    Description

      The following code pattern causes a java.lang.VerifyError.

      Java base class with eval method
      Groovy subclass of the java base class with also implements the eval method
      Groovy subclass eval method calls another method which calls back into the java base class eval method
      If the call to the java base class eval is enclosed in an if statement a VerifyError is generated by the jvm.

      This happens on sun 1.4.2_12 jvm on windows.

      The following code produces the exception.

      java.lang.VerifyError: (class: TestValidationExceptionChild, method: doSomething signature: (Ljava/lang/String;)Ljava/lang/Object Inconsistent stack height 1 != 0
      at java.lang.Class.getDeclaredConstructors0(Native Method)
      at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
      at java.lang.Class.getConstructor0(Unknown Source)
      at java.lang.Class.newInstance0(Unknown Source)
      at java.lang.Class.newInstance(Unknown Source)
      at TestValidationExceptionBase.main(TestValidationExceptionBase.java:20)

      If the groovy script call to super.eval(s) in the doSomething method is commented out and a level of indirection put in by calling the doSomething2 method the code works fine. The output is:

      In the groovy child class eval() with: hello world
      In the child class doSomething() with: hello world
      In the groovy child class doSomething2() with: hello world
      In the java base class eval() with: hello world

      /*

      • Groovy class which calls back into the base class
        */

      import TestValidationExceptionBase;

      public class TestValidationExceptionChild extends TestValidationExceptionBase {

      public void eval( String s )

      { println "In the groovy child class eval() with: " + s doSomething( s ) return }

      def doSomething2( String s )

      { println "In the groovy child class doSomething2() with: " + s super.eval( s ) }

      def doSomething( String s ) {
      println "In the child class doSomething() with: " + s
      if ( true )

      { super.eval( s ) // this line causes java.lang.VerifyError //doSomething2( s ) // commenting out the above line and uncomment this line works }


      }
      }

      /*

      • Java base class with main method to run the test
        */

      import java.io.File;
      import groovy.lang.*;

      public class TestValidationExceptionBase
      {

      public void eval( String s )

      { System.out.println( "In the java base class eval() with: " + s ); return; }

      static public void main( String args[ ] ) {
      try {
      GroovyClassLoader gcl = new GroovyClassLoader();
      Class groovyClass = gcl.parseClass( new File( "TestValidationExceptionBase.groovy" ) );
      GroovyObject o = (GroovyObject)groovyClass.newInstance();
      Object[] methodArgs =

      { "hello world" }

      ;
      o.invokeMethod( "eval", methodArgs );

      }
      catch( Throwable e )

      { e.printStackTrace(); }

      }

      }

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            cbarton Chris Barton
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: