Skip to content
Browse files

GROOVY-5286: Fixed constant pool being used even for non static fields

  • Loading branch information...
1 parent b550d82 commit f51879debc47c1a0088f2bbbc6ec9062406045b9 @melix melix committed Feb 8, 2012
View
2 src/main/groovy/inspect/swingui/AstNodeToScriptAdapter.groovy
@@ -448,7 +448,7 @@ class AstNodeToScriptVisitor extends PrimaryClassNodeOperation implements Groovy
Expression exp = node.initialValueExpression
if (exp instanceof ConstantExpression) exp = Verifier.transformToPrimitiveConstantIfPossible(exp)
ClassNode type = exp?.type
- if (Modifier.isStatic(node.modifiers)
+ if (Modifier.isStatic(node.modifiers) && Modifier.isFinal(node.getModifiers())
&& exp instanceof ConstantExpression
&& type == node.type
&& ClassHelper.isStaticConstantInitializerType(type)) {
View
1 src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -402,6 +402,7 @@ public void visitField(FieldNode fieldNode) {
}
Object value = cexp!=null && ClassHelper.isStaticConstantInitializerType(cexp.getType())
&& cexp.getType().equals(t)
+ && fieldNode.isStatic() && fieldNode.isFinal()
?cexp.getValue() // GROOVY-5150
:null;
if (value!=null) {
View
2 src/main/org/codehaus/groovy/classgen/Verifier.java
@@ -953,7 +953,7 @@ protected void addFieldInitialization(List list, List staticList, FieldNode fiel
if (initialValueExpression instanceof ConstantExpression) {
ConstantExpression cexp = (ConstantExpression) initialValueExpression;
cexp = transformToPrimitiveConstantIfPossible(cexp);
- if (ClassHelper.isStaticConstantInitializerType(cexp.getType()) && cexp.getType().equals(fieldNode.getType())) {
+ if (fieldNode.isFinal() && ClassHelper.isStaticConstantInitializerType(cexp.getType()) && cexp.getType().equals(fieldNode.getType())) {
return; // GROOVY-5150: primitive type constants will be initialized directly
}
staticList.add(0, statement);
View
1 src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -334,6 +334,7 @@ private void printField(PrintWriter out, FieldNode fieldNode, boolean isInterfac
valueExpr = Verifier.transformToPrimitiveConstantIfPossible((ConstantExpression) valueExpr);
}
if (valueExpr instanceof ConstantExpression
+ && fieldNode.isStatic() && fieldNode.isFinal()
&& ClassHelper.isStaticConstantInitializerType(valueExpr.getType())
&& valueExpr.getType().equals(fieldNode.getType())) {
// GROOVY-5150 : Initialize value with a dummy constant so that Java cross compiles correctly

0 comments on commit f51879d

Please sign in to comment.
Something went wrong with that request. Please try again.