Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2503 MOP 2.0 design inflluencing issues
  3. GROOVY-2971

MetaClassImpl.respondsTo() does not work properly with methods that have Class parameters.

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.5.6, 1.6-beta-1
    • None
    • groovy-runtime
    • None

    Description

      Current implementions or respondsTo() in MetaClassImpl do not find methods, that have parameters of type Class, when used with argument values and not with argument types.

      Example:

      class A {
      def method(Class c, int i)

      { 'blabla' }

      }

      a = new A()

      assert [] == a.metaClass.respondsTo(a,'method',String,42) // passes, but shouldn't pass.

      The problem seems to be in a method called castArgumentsToClassArray() residing now in MetaClassHelper class that is not clear about its purpose - handling parameter values and/or parameter types and thus does not convert Class parameters to Class<Class>. As a result, this method does not function if a parameter is of type Class but is meant to be a parameter value.

      Proposed solution:
      a) Make clear respondsTo() allows only Class parameters and implement it accordingly.
      b) (Optional but useful) Create another variant of that method that accepts parameter values and converts all parameters to their respective types before searching the method. (Can't be overloaded since Class parameters may be given in an Object[] array and one cannot tell if they are actual parameter types or parameter values of type Class.)

      Attachments

        Activity

          People

            Unassigned Unassigned
            jstaudemeyer Jörg Staudemeyer
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: