Details
Description
Given the following class compiled to a jar and placed in the Java extensions directory, 1.0-JSR-4 cannot access "Foo.Bar", while 1.0-JSR-2 could.
------------------------------------------------------
public class Foo {
public static int foo = 5;
public static class Bar
{ public static int bar = 7; }public static void main(String[] args)
{ System.out.println("foo="+foo); System.out.println("bar="+Bar.bar); }}
----------------------------------------------------------
Here are the results from my command line shell using groovy-all-1.0-jsr-02.jar, which works as expected:
> Foo
class Foo
> Foo.foo
5
> Foo.main(null)
foo=5
bar=7
null
> Foo.Bar
class Foo$Bar
> Foo.Bar.bar
7
This is the result using groovy-all-1.0-jsr-04.jar, which is unable to access Foo.Bar either directly or via Class.forName(). It appears to be parsing Foo.Bar as equivalent to Foo.class.Bar, and thus applying the ".Bar" to the Class instance for Foo.
> Foo
class Foo
> Foo.foo
5
> Foo.main(null)
foo=5
bar=7
null
> Foo.Bar
groovy.lang.MissingFieldException: No such field: Bar for class: java.lang.Class
at groovy.lang.MetaClassImpl.getAttribute(MetaClassImpl.java:1074)
at groovy.lang.MetaClassImpl.getStaticProperty(MetaClassImpl.java:1308)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:707)
at org.codehaus.groovy.runtime.Invoker.getProperty(Invoker.java:727)
at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:206)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:295)
at Script5.run(Script5.groovy)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:506)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:484)
at QShell.runCommandLineLoop(QShell.java:57)
at QShell.start(QShell.java:38)
...
> Foo.Bar.bar
groovy.lang.MissingFieldException: No such field: Bar for class: java.lang.Class
at groovy.lang.MetaClassImpl.getAttribute(MetaClassImpl.java:1074)
at groovy.lang.MetaClassImpl.getStaticProperty(MetaClassImpl.java:1308)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:707)
at org.codehaus.groovy.runtime.Invoker.getProperty(Invoker.java:727)
at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:206)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:295)
at Script6.run(Script6.groovy)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:506)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:484)
at QShell.runCommandLineLoop(QShell.java:57)
at QShell.start(QShell.java:38)
...
> Class.forName("Foo.Bar")
java.lang.ClassNotFoundException: Foo.Bar
at java.lang.ClassLoader.findClass(ClassLoader.java:341)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:634)
at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:705)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at gjdk.java.lang.Class_GroovyReflector.invoke(Unknown Source)
at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:584)
at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:485)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:136)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
at Script7.run(Script7.groovy)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:506)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:484)
at QShell.runCommandLineLoop(QShell.java:57)
at QShell.start(QShell.java:38)
...