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

StackOverflow Exception when calling super.method, which returns an instance of the corresponding class.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.10, 2.0-beta-2, 1.8.6
    • 2.2.1
    • groovy-jdk
    • None
    • Windows 7, IntelliJ IDEA

    Description

      You get a StackOverflow Exception when running following code:

      A.groovy
      abstract class A {
          A attach(){
              System.out.println( "A does something else");
              return this;
          }
      }
      
      B.groovy
      class B extends A {
          @Override
          B attach(){
              System.out.println("B does something else");
              return (B) super.attach();
          }
      }
      
      C.groovy
      class C extends B {
          @Override
          C attach(){
              System.out.println("C does something else");
              return (C) super.attach();
          }
      }
      
      Test.groovy
      C c = new C(); c.attach();
      

      This bug only occurs when the depth of the class hierarchy exceeds two classes.
      Moreover this bug seems depend on the method name! If you try attachMe() as method name the Stackoverflow Exception won't be raised.
      The whole ErrorOutput can be found attached.

      Error.output
      C does something else
      C does something else
      C does something else
      C does something else
      Exception in thread "main" java.lang.StackOverflowError
      	at groovy.lang.MetaClassImpl.getMetaProperty(MetaClassImpl.java:2441)
      	at groovy.lang.MetaClassImpl.getMetaProperty(MetaClassImpl.java:2415)
      	at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1510)
      	at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3308)
      	at org.codehaus.groovy.runtime.callsite.ClassMetaClassGetPropertySite.getProperty(ClassMetaClassGetPropertySite.java:48)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227)
      	at C.attach(C.groovy:20)
      	at C.attach(C.groovy)
      	at B.attach(B.groovy)
      	at C.super$3$attach(C.groovy)
      	at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1047)
      	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:128)
      	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:148)
      

      Attachments

        1. erroroutput.txt
          67 kB
          Stefan Leonhartsberger

        Activity

          People

            blackdrag Jochen Theodorou
            stefan_leo Stefan Leonhartsberger
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: