Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.5.4, 2.5.14
-
None
-
JDK: openjdk version "1.8.0_265"(Zulu 8.48.0.53-CA-macosx) (build 1.8.0_265-b11)
Description
After upgrading 2.5.3 to 2.5.4, observing the following error in my project:
General error during class generation: java.lang.Long cannot be cast to java.lang.String
java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
at org.apache.groovy.ast.tools.ExpressionUtils.transformBinaryConstantExpression(ExpressionUtils.java:86)
at org.apache.groovy.ast.tools.ExpressionUtils.transformInlineConstants(ExpressionUtils.java:248)
at org.codehaus.groovy.classgen.Verifier.addFieldInitialization(Verifier.java:1163)
at org.codehaus.groovy.classgen.Verifier.addInitialization(Verifier.java:1048)
at org.codehaus.groovy.classgen.Verifier.addInitialization(Verifier.java:999)
at org.codehaus.groovy.classgen.Verifier.visitClass(Verifier.java:250)
at org.codehaus.groovy.control.CompilationUnit$18.call(CompilationUnit.java:811)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1084)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:640)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:618)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:595)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:574)
...
This can be solved with:
From:
(String) ((ConstantExpression) left).getValue()
To:
String.valueOf(((ConstantExpression) left).getValue())
Diff is as follows:
diff --git a/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java b/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java
index 4aa67a52cb..7057f14982 100644
— a/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java
+++ b/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java
@@ -83,7 +83,7 @@ public final class ExpressionUtils {
Expression left = transformInlineConstants(be.getLeftExpression(), targetType);
Expression right = transformInlineConstants(be.getRightExpression(), targetType);
if (left instanceof ConstantExpression && right instanceof ConstantExpression)
If you want, I can raise a PR for this.