Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Critical
-
Resolution: Fixed
-
Affects Version/s: 1.1-beta-3
-
Fix Version/s: 1.1-rc-1
-
Component/s: None
-
Labels:None
-
Environment:JDK 1.5.0 / JDK 1.6.0; Windows Vista
-
Number of attachments :
Description
Looks as if they compile properly, but lead to an error at load time. Groovysh session transcript follows.
Groovy Shell (1.1-beta-3, JVM: 1.6.0_01-b06)
Type 'go' to execute statements; Type 'help' for more information.
groovy> enum E
groovy> go
ERROR: groovy.lang.GroovyRuntimeException: Failed to create Script instance for class: class E. Reason: java.lang.InstantiationException: E
groovy.lang.GroovyRuntimeException: Failed to create Script instance for class: class E. Reason: java.lang.InstantiationException: E
at org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:385)
at groovy.lang.GroovyShell.parse(GroovyShell.java:500)
at groovy.lang.GroovyShell.parse (GroovyShell.java:480)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:458)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:434)
at groovy.ui.InteractiveShell.run(InteractiveShell.java :289)
at groovy.ui.InteractiveShell.main(InteractiveShell.java:101)
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:597)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader (GroovyStarter.java:101)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130)
Caused by: java.lang.InstantiationException: E
at java.lang.Class.newInstance0(Class.java:340)
at java.lang.Class.newInstance(Class.java:308)
at org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:366)
... 12 more
The compiler returns an Enum object, whereas the InvokerHelper is expecting a Script or a GroovyObject.
I propose we return the Class object for the enum in this instance (IMHO the other sensible option being to return null). This will only be visible in scripts where the only expression is a single enum statement, so I don't think it can be tripped elsewhere accidentally.