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 2022/09/03 14:03:00 UTC

[jira] [Updated] (GROOVY-10746) Calling method in Super class causes java.lang.StackOverflowError with Java 1.8

     [ https://issues.apache.org/jira/browse/GROOVY-10746?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles updated GROOVY-10746:
---------------------------------
    Labels: StackOverflowError  (was: )

> Calling method in Super class causes java.lang.StackOverflowError with Java 1.8
> -------------------------------------------------------------------------------
>
>                 Key: GROOVY-10746
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10746
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.17, 3.0.12, 4.0.4
>            Reporter: Troy Harris
>            Priority: Major
>              Labels: StackOverflowError
>
> Consider the class SortedProperties below which extends java.util.Properties and overrides Properties.keys().
> {code:java}
> import java.util.Enumeration;
> import java.util.Collections;
> class SortedProperties extends Properties {
>     
>   @Override 
>   public synchronized Enumeration keys() {
>      Enumeration keysEnum = super.keys();
>      Vector keyList = new Vector();
>      while(keysEnum.hasMoreElements()){
>        keyList.add(keysEnum.nextElement());
>      }
>      Collections.sort(keyList);
>      return keyList.elements();
>   }
> }   {code}
> In this scenario the Groovy class above is compiled with Groovy 3.0.12 and JDK 11 but using the flag "--release 1.8" for JDK 1.8 compatibility.
> Attempting to call the overridden keys() method from the following TestGroovy class (compiled the same way) will yield a StackOverflowException when running with Java 1.8.  This error is not reproduceable when running with Java 11.
> {code:java}
> import java.util.Properties;
> public class TestGroovy {
>   public static void main(String[] args) {
>         SortedProperties properties = new SortedProperties();
>         properties.setProperty("FirstName", "John");
>         properties.setProperty("LastName", "Doe");
>         properties.keys();
>     }
> } {code}
> Truncated Stacktrace:
> {noformat}
> Exception in thread "main" java.lang.StackOverflowError
>         at org.codehaus.groovy.runtime.metaclass.MetaMethodIndex.getMethods(MetaMethodIndex.java:210)
>         at groovy.lang.MetaClassImpl.getMethodWithCaching(MetaClassImpl.java:1371)
>         at groovy.lang.MetaClassImpl.getMetaMethod(MetaClassImpl.java:1280)
>         at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1132)
>         at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:144)
>         at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:164)
>         at com.sas.appserver.utils.SortedProperties.keys(SortedProperties.groovy:12)
>         at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:498)
>         at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
>         at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
>         at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1268)
>         at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:144)
>         at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:164)
>         at com.sas.appserver.utils.SortedProperties.keys(SortedProperties.groovy:12)
>         at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:498)
>         at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
>         at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
>         at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1268)
>         at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:144)
>         at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:164)
>         at com.sas.appserver.utils.SortedProperties.keys(SortedProperties.groovy:12){noformat}
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)