Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.5.17, 3.0.12, 4.0.4
-
None
Description
Consider the class SortedProperties below which extends java.util.Properties and overrides Properties.keys().
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(); } }
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.
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(); } }
Truncated Stacktrace:
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.foo.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.foo.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.foo.SortedProperties.keys(SortedProperties.groovy:12)