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

CachedClass.CachedMethodComparatorWithString doesn't work on non Sun JDK

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 1.5.4
    • Fix Version/s: 1.5.5, 1.6-beta-1
    • Component/s: None
    • Labels:
      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

        Attachments

          Activity

            People

            • Assignee:
              ait Alex Tkachman
              Reporter:
              mguillemot@yahoo.fr Marc Guillemot
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: