Fix SpEL compilation for non trivial elvis operand

Issue: SPR-17214
This commit is contained in:
Juergen Hoeller
2018-09-07 13:12:53 +02:00
parent 8ce9236b0f
commit 6a5d986b33
2 changed files with 121 additions and 47 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -77,8 +77,10 @@ public class Elvis extends SpelNodeImpl {
public void generateCode(MethodVisitor mv, CodeFlow cf) {
// exit type descriptor can be null if both components are literal expressions
computeExitTypeDescriptor();
cf.enterCompilationScope();
this.children[0].generateCode(mv, cf);
CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0));
cf.exitCompilationScope();
Label elseTarget = new Label();
Label endOfIf = new Label();
mv.visitInsn(DUP);
@@ -91,10 +93,12 @@ public class Elvis extends SpelNodeImpl {
mv.visitJumpInsn(IFEQ, endOfIf); // if not empty, drop through to elseTarget
mv.visitLabel(elseTarget);
mv.visitInsn(POP);
cf.enterCompilationScope();
this.children[1].generateCode(mv, cf);
if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) {
CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0));
}
cf.exitCompilationScope();
mv.visitLabel(endOfIf);
cf.pushDescriptor(this.exitTypeDescriptor);
}