Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.5.6
-
Fix Version/s: 1.6-rc-1, 1.5.8, 1.7-beta-1
-
Component/s: Groovysh
-
Labels:None
-
Environment:Mac OS X Leopard 10.5.5
-
Patch Submitted:Yes
-
Number of attachments :
Description
groovysh does not run when CLASSPATH includes embeddable/groovy-all.jar. groovy, groovyc, and groovyConsole work fine.
$ echo $CLASSPATH
$ groovysh
Groovy Shell (1.5.6, JVM: 1.5.0_16-133)
Type 'help' or '\h' for help.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
groovy:000> \q
$ export CLASSPATH=$GROOVY_HOME/embeddable/groovy-all-1.5.6.jar
$ groovysh
java.lang.reflect.InvocationTargetException
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:585)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:101)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130)
Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'org.codehaus.groovy.tools.shell.util.HelpFormatter@d4f27' with class 'org.codehaus.groovy.tools.shell.util.HelpFormatter' to class 'org.apache.commons.cli.HelpFormatter'
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:340)
at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:1997)
at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2591)
at groovy.lang.MetaClassImpl.setProperties(MetaClassImpl.java:1291)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1268)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1185)
at org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:809)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeNewN(ScriptBytecodeAdapter.java:230)
at org.codehaus.groovy.tools.shell.Main.main(Main.groovy:43)
Hi,
Attaching a patch that is solving this issue.
The casting exception was coming in groovysh with groovy-all.jar on the classpath because the formatter created by org.codehaus.groovy.tools.shell.Main is of the type org.codehaus.groovy.tools.shell.util.HelpFormatter. This class extends org.apache.commons.cli.HelpFormatter but the JarJar step in groovy build, which creates embeddable JAR, changes it to groovyjarjarcommonscli.HelpFormatter.
This formatter gets passed to CliBuilder, which still uses the type org.apache.commons.cli.HelpFormatter as the JarJar step excludes CliBuilder to fix JIRA
GROOVY-2295. Hence the type-mismatch and the casting exception.The attached fix patch also excludes org.codehaus.groovy.tools.shell.util.HelpFormatter from JarJar bytecode modification, which makes the type used in this HelpFormatter and CliBuilder same.
rgds,
Roshan