Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Won't Fix
-
1.0-RC-1
-
None
-
Java / WindowsXP
Description
Comparing a value 60 of type Long with a value 4 of type String throws a ClassCastException.
Stack Trace:
60
4.0
Exception in thread "main" java.lang.ClassCastException: java.lang.String
at java.lang.Long.compareTo(Long.java:34)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.compareTo(DefaultTypeTransformation.java:481)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.compareTo(ScriptBytecodeAdapter.java:732)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.compareGreaterThan(ScriptBytecodeAdapter.java:750)
at Script1.run(Script1.groovy:1)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:484)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:459)
at groovyprj.TestEmbeddedGroovy.main(TestEmbeddedGroovy.java:29)
The code to reproduce (using embedded groovy)
//call groovy expressions from Java code
Binding binding = new Binding() {
public Object getVariable(String key) {
if (key.equals("lValue"))
if (key.equals("rValue"))
{ return "4.0"; } return super.getVariable(key);
}
};
GroovyShell shell = new GroovyShell(binding);
String expr = "println lValue; println rValue; println lValue > rValue; return lValue+rValue";
Object value = shell.evaluate(expr);
System.out.println(value);