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

GroovyRuntimeException thrown Ambiguous method overloading when accessing metaClas of java.lang.String

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.6-rc-1, 1.6
    • 1.6.4, 1.7-beta-1
    • groovy-jdk
    • None
    • Ubuntu Linux, jdk 1.6, Eclipse 3.4.1

    Description

      Running the following code cause an Ambiguous method overloading exception:

      str = 'hello'
      methodName = 'toUpperCase'

      methodOfInterest = str.metaClass.getMetaMethod(methodName)
      println methodOfInterest.invoke(str)

      Expected output: HELLO

      Exception details:

      Exception in thread "main" groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method org.codehaus.groovy.runtime.HandleMetaClass#getMetaMethod.
      Cannot resolve which method to invoke for

      {class java.lang.String}

      due to overlapping prototypes between:

      {class java.lang.String, class [Ljava.lang.Object;} {class java.lang.String, class [Ljava.lang.Class;}

      at groovy.lang.MetaClassImpl.chooseMostSpecificParams(MetaClassImpl.java:2866)
      at groovy.lang.MetaClassImpl.chooseMethod(MetaClassImpl.java:2819)
      at groovy.lang.MetaClassImpl.getNormalMethodWithCaching(MetaClassImpl.java:1228)
      at groovy.lang.MetaClassImpl.getMethodWithCaching(MetaClassImpl.java:1131)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:910)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
      at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:736)
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:719)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:163)
      at MOPUsingMetaMethod.run(MOPUsingMetaMethod.groovy:4)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
      at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:736)
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:719)
      at org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:381)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
      at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1301)
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:710)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:163)
      at MOPUsingMetaMethod.main(MOPUsingMetaMethod.groovy)

      This functionality does work in groovy 1.5.7 so appears to have regressed in 1.6.0.

      Using the pickMethod instead of getMetaMethod produces the expected output.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            jparkin James Parkin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: