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

If CompileStatic is used, metaClass variable shadowing triggers exception when invoking closures

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4.12
    • None
    • None

    Description

      See the small attached example class.

      Problem arises if you define a local variable and name it "metaClass", then call a closure that accepts some parameters like map.each

      { key, value -> ... }

      .

      When the code gets to Closure.call(Object... args) it executes:

      return (V) getMetaClass().invokeMethod(this,"doCall",args);

      only now getMetaClass() returns the shadowed metaClass variable, not the Closure's metaClass and an exception is thrown if the class that the external metaClass belongs to does not define a doCall(args) method.

      This seems to be happening only with @CompileStatic

      Renaming the local variable from metaClass to anything else works around the problem.

      Attachments

        1. Bug.groovy
          0.7 kB
          Sergio Nalin

        Activity

          People

            Unassigned Unassigned
            sergio.nalin Sergio Nalin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: