Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-5989 Inner Class Issues
  3. GROOVY-5351

Malformed class names for closures in inner classes

    XMLWordPrintableJSON

    Details

    • Type: Sub-task
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.4, 1.8.6
    • Fix Version/s: 2.4.0-beta-4
    • Component/s: class generator
    • Labels:
    • Environment:
      OS X, Groovy 1.8.4, Java version 1.6.0_29

      Description

      The class names generated for closures in inner classes break Class.getSimpleName()

      For example, the closure passed to .each in this example has name Example$_Inner_closure1.class:

      public class Example {
          private class Inner {
              def _ = [1, 2, 3].each {}
          }
      }
      

      Calling getSimpleName() on this class (e.g. as done by Weld on startup) throws a java.lang.InternalError:

      Caused by: java.lang.InternalError: Malformed class name
      	at java.lang.Class.getSimpleName(Class.java:1133) [:1.6.0_29]
      	at java.lang.Class.isAnonymousClass(Class.java:1188) [:1.6.0_29]
      

      I believe the class name is expected to be in the format Example$Inner$closure1.

      I've attached a test case to demonstrate the problem - extract the archive, cd to groovy-closure-classname-test and run mvn test. The test uses Weld to inject a ClosureClassNameTest instance, but fails when Weld calls getSimpleName() on the class for the closure on line 10.

        Attachments

        1. FileCipher.groovy
          2 kB
          Paul Sideleau
        2. closure-classname.tar.gz
          1 kB
          Samuel James Corbett

          Issue Links

            Activity

              People

              • Assignee:
                blackdrag Jochen Theodorou
                Reporter:
                sjcorbett Samuel James Corbett
              • Votes:
                4 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: