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

Static closures have wrong owner object

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-5
    • 1.0-beta-10
    • class generator
    • None

    Description

      Static closures have their owner object set to the equivalent of java.lang.Class.class instead of the class they're contained in.

      Example:

      class Test {
      static staticMethod()

      { println("hello world") }

      static void main(args) {
      c =

      { staticMethod() }

      c()
      }
      }

      Fails with:

      Caught: groovy.lang.MissingMethodException: No such method: staticMethod for class: Test$1 with arguments: []

      Patch:

      Index: ClassGenerator.java
      ===================================================================
      retrieving revision 1.175
      diff -u -r1.175 ClassGenerator.java
      — ClassGenerator.java 25 Mar 2004 19:29:58 -0000 1.175
      +++ ClassGenerator.java 26 Mar 2004 14:52:49 -0000
      @@ -1126,9 +1126,6 @@

      ClassNode owner = innerClass.getOuterClass();
      String ownerTypeName = owner.getName();

      • if (classNode.isStaticClass() || isStaticMethod()) { - ownerTypeName = "java.lang.Class"; - }

      passingClosureParams = true;
      List constructors = innerClass.getDeclaredConstructors();

      Attachments

        Activity

          People

            jstrachan James Strachan
            pmbrant Peter Brant
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: