Skip to content

Commit abc3cc4

Browse files
committed
Ensure correct boxing in compiled code for OpEq with primitives
Without this change when the operands to an == are a mix of a reference type and a primitive, the failure to box the primitive would result in a verifyerror when the compiled code is loaded. Issue: SPR-12557
1 parent 3125ef7 commit abc3cc4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

spring-expression/src/main/java/org/springframework/expression/spel/ast/OpEQ.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,13 @@ else if (targetType=='I' || targetType=='Z') {
112112
}
113113
else {
114114
getLeftOperand().generateCode(mv, cf);
115+
if (leftPrim) {
116+
CodeFlow.insertBoxIfNecessary(mv, leftDesc.charAt(0));
117+
}
115118
getRightOperand().generateCode(mv, cf);
119+
if (rightPrim) {
120+
CodeFlow.insertBoxIfNecessary(mv, rightDesc.charAt(0));
121+
}
116122
Label leftNotNull = new Label();
117123
mv.visitInsn(DUP_X1); // Dup right on the top of the stack
118124
mv.visitJumpInsn(IFNONNULL,leftNotNull);

spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,20 @@ public void opGe() throws Exception {
12851285

12861286
@Test
12871287
public void opEq() throws Exception {
1288-
1288+
String tvar = "35";
1289+
expression = parse("#root == 35");
1290+
Boolean bb = (Boolean)expression.getValue(tvar);
1291+
System.out.println(bb);
1292+
assertFalse((Boolean)expression.getValue(tvar));
1293+
assertCanCompile(expression);
1294+
assertFalse((Boolean)expression.getValue(tvar));
1295+
1296+
expression = parse("35 == #root");
1297+
expression.getValue(tvar);
1298+
assertFalse((Boolean)expression.getValue(tvar));
1299+
assertCanCompile(expression);
1300+
assertFalse((Boolean)expression.getValue(tvar));
1301+
12891302
TestClass7 tc7 = new TestClass7();
12901303
expression = parse("property == 'UK'");
12911304
assertTrue((Boolean)expression.getValue(tc7));

0 commit comments

Comments
 (0)