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

StackOverflow Exception when calling super.method when extending java class

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.2.1
    • 4.0.0-rc-2
    • groovy-runtime
    • None

    Description

      You can get StackOverflowError when running following code:

      A.java
      package test.java;
      
      public abstract class A<T> {
          protected String getText(T arg){
              return "Class A.";
          }
      }
      
      C.java
      package test.java;
      
      public class C extends A<String> {
          @Override
          protected String getText(String arg){
              return super.getText(arg) + "Class C. ";
          }
      }
      
      D.groovy
      package test.java
      
      class D extends C {
          @Override
          protected String getText(String arg) {
              return super.getText(arg) + 'Class D.';
          }
      
          public static void main(String[] args) {
              D d = new D();
              String res = d.getText(null);
              println(res);
          }
      }
      

      This bug occurs when class A is generic and method has parameterized argument.

      Output
      Exception in thread "main" java.lang.StackOverflowError
      	at test.java.D.getText(D.groovy)
      	at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:601)
      	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:1085)
      	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:128)
      	at test.java.D.getText(D.groovy:6)
      	at test.java.D.getText(D.groovy)
      

      This bug looks similar to GROOVY-5385

      Attachments

        1. erroroutput.txt
          67 kB
          Aleh Bich

        Issue Links

          Activity

            People

              emilles Eric Milles
              alehbich Aleh Bich
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: