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
This commit is contained in:
Andy Clement 2014-12-18 13:46:55 -08:00
parent 3125ef784c
commit abc3cc4dc4
2 changed files with 20 additions and 1 deletions

View File

@ -112,7 +112,13 @@ public class OpEQ extends Operator {
}
else {
getLeftOperand().generateCode(mv, cf);
if (leftPrim) {
CodeFlow.insertBoxIfNecessary(mv, leftDesc.charAt(0));
}
getRightOperand().generateCode(mv, cf);
if (rightPrim) {
CodeFlow.insertBoxIfNecessary(mv, rightDesc.charAt(0));
}
Label leftNotNull = new Label();
mv.visitInsn(DUP_X1); // Dup right on the top of the stack
mv.visitJumpInsn(IFNONNULL,leftNotNull);

View File

@ -1285,7 +1285,20 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
@Test
public void opEq() throws Exception {
String tvar = "35";
expression = parse("#root == 35");
Boolean bb = (Boolean)expression.getValue(tvar);
System.out.println(bb);
assertFalse((Boolean)expression.getValue(tvar));
assertCanCompile(expression);
assertFalse((Boolean)expression.getValue(tvar));
expression = parse("35 == #root");
expression.getValue(tvar);
assertFalse((Boolean)expression.getValue(tvar));
assertCanCompile(expression);
assertFalse((Boolean)expression.getValue(tvar));
TestClass7 tc7 = new TestClass7();
expression = parse("property == 'UK'");
assertTrue((Boolean)expression.getValue(tc7));