Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.0-beta-9
-
None
-
None
-
Groovy 1.0-beta-9
Windows 2000 SP4
Java 1.4.2_06
Description
When a static method in an inner class attempts to access a non-static variable defined within that class, a less-than-helpful Exception message is generated. Now granted, a static method should not try to access non-static attributes or methods of the class, but this mistake is easy to make and in the Java Language the condition is caught by the compiler. Groovy should also make this common mistake easy to identify.
Example:
---------- script: StaticError.groovy ----------
class SomeClass {
Map data = new HashMap()
public static void staticMethod(key, value)
{ data.put(key, value) }}
------------------ end script ------------------
"> groovy -d StaticError.groovy" generates the following error message:
Caught: General error during class generation: java.lang.NullPointerException
General error during class generation: java.lang.NullPointerException
at org.codehaus.groovy.control.ProcessingUnit.fail(ProcessingUnit.java:466)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:841)
at org.codehaus.groovy.control.CompilationUnit.classgen(CompilationUnit.java:525)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:432)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:234)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:203)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:153)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:221)
at java.security.AccessController.doPrivileged(Native Method)
at groovy.lang.GroovyShell.run(GroovyShell.java:219)
at groovy.lang.GroovyShell.run(GroovyShell.java:163)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:366)
at groovy.ui.GroovyMain.run(GroovyMain.java:232)
at groovy.ui.GroovyMain.process(GroovyMain.java:218)
at groovy.ui.GroovyMain.main(GroovyMain.java:122)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.codehaus.classworlds.Launcher.launchStandard(Launcher.java:410)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:344)
at org.codehaus.classworlds.Launcher.main(Launcher.java:461)