You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2016/02/17 06:54:18 UTC
[jira] [Comment Edited] (GROOVY-7757) Malformed class names for
closures in inner classes
[ https://issues.apache.org/jira/browse/GROOVY-7757?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15149931#comment-15149931 ]
Paul King edited comment on GROOVY-7757 at 2/17/16 5:53 AM:
------------------------------------------------------------
Looks a little strange. The following works on master:
{code}
class Foo {
boolean allHaveCapitals = ["bAr", "baZ"].every{ word -> word.any{ it.toCharacter().isUpperCase() } }
}
assert new Foo().allHaveCapitals
assert Foo$_closure1.simpleName == '_closure1'
assert Foo$_closure1$_closure2.simpleName == '_closure2'
{code}
As does this:
{code}
class Foo {
private class Inner {
def _ = [1, 2, 3].each {}
}
}
assert getClass().classLoader.loadedClasses*.name.contains('Foo$Inner$_closure1')
assert Foo$Inner$_closure1.simpleName == '_closure1'
{code}
was (Author: paulk):
Looks a little strange. The following works on master:
{code}
class Foo {
boolean allHaveCapitals = ["bAr", "baZ"].every{ word -> word.any{ it.toCharacter().isUpperCase() } }
}
assert new Foo().allHaveCapitals
assert Foo$_closure1.simpleName == '_closure1'
assert Foo$_closure1$_closure2.simpleName == '_closure2'
{code}
> Malformed class names for closures in inner classes
> ---------------------------------------------------
>
> Key: GROOVY-7757
> URL: https://issues.apache.org/jira/browse/GROOVY-7757
> Project: Groovy
> Issue Type: Sub-task
> Components: class generator
> Affects Versions: 2.4.5
> Reporter: Sam Corbett
>
> 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:
> {code}
> public class Example {
> private class Inner {
> def _ = [1, 2, 3].each {}
> }
> }
> {code}
> Calling getSimpleName() on this class (e.g. as done by [Weld|http://seamframework.org/Weld] on startup) throws a java.lang.InternalError:
> {code}
> 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]
> {code}
> 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.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)