Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Fixed
-
1.5.4
-
None
-
None
Description
CachedClass.CachedMethodComparatorWithString isn't a correct Comparator implementation as it has expectations on the order of the arguments given to the compare method.
The JDK says "The implementor must ensure that sgn(compare(x, y)) == -sgn(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if
compare(y, x) throws an exception.)"
This leads to exceptions like this one:
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to org.codehaus.groovy.reflection.CachedMethod
at org.codehaus.groovy.reflection.CachedClass$CachedMethodComparatorWithString.compare(CachedClass.java:374)
at java.util.Collections.compare(libgcj.so.7rh)
at java.util.Arrays.binarySearch(libgcj.so.7rh)
at groovy.lang.MetaClassImpl$1MOPIter.methodNameAction(MetaClassImpl.java:423)
at groovy.lang.MetaClassImpl$MethodIndexAction.iterate(MetaClassImpl.java:2564)
at groovy.lang.MetaClassImpl.replaceWithMOPCalls(MetaClassImpl.java:471)
at groovy.lang.MetaClassImpl.fillMethodIndex(MetaClassImpl.java:224)
at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:2469)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getGlobalMetaClass(MetaClassRegistryImpl.java:248)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.access$100(MetaClassRegistryImpl.java:45)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl$LocallyKnownClasses.getFromGlobal(MetaClassRegistryImpl.java:112)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl$LocallyKnownClasses.getMetaClass(MetaClassRegistryImpl.java:88)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl$MyThreadLocal.getMetaClass(MetaClassRegistryImpl.java:356)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:260)
at org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:728)
at groovy.lang.GroovyObjectSupport.<init>(GroovyObjectSupport.java:32)
at groovy.lang.Script.<init>(Script.java:40)
at groovy.lang.Script.<init>(Script.java:37)
at generateDtd.<init>(generateDtd.groovy)
at java.lang.Class.newInstance(libgcj.so.7rh)
at org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:416)
This is a variation of http://jira.codehaus.org/browse/GROOVY-2399