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

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 2.2.2
    • 2.3.0
    • groovy-jdk
    • None
    • Mac OSX Mavericks, 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.
      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
          Romaric Philogene

        Activity

          People

            blackdrag Jochen Theodorou
            evox Romaric Philogene
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: