Introduce missing tests for immediate SpEL compilation for Elvis operator

This commit is contained in:
Sam Brannen
2026-04-12 17:11:07 +02:00
parent a3705632c1
commit 28f78f435e
2 changed files with 22 additions and 1 deletions
@@ -98,7 +98,11 @@ public class Elvis extends SpelNodeImpl {
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
// exit type descriptor can be null if both components are literal expressions
// If both elements are literals and the expression was not previously
// evaluated in interpreted mode -- or if getValueInternal() did not
// properly invoke computeExitTypeDescriptor() -- we may get here without
// the exit descriptor having been computed, so we must ensure the exit
// descriptor has been computed before proceeding.
computeExitTypeDescriptor();
cf.enterCompilationScope();
@@ -1470,6 +1470,23 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
assertThat(getAst().getExitDescriptor()).isEqualTo("Ljava/lang/String");
}
@Test
void elvisWithImmediateCompilation() {
expression = parser.parseExpression("'a' ?: 'b'");
// Both literals, so we can compile immediately without having previously
// evaluated the expression.
assertCanCompile(expression);
assertThat(expression.getValue(String.class)).isEqualTo("a");
assertThat(getAst().getExitDescriptor()).isEqualTo("Ljava/lang/String");
expression = parser.parseExpression("null ?: 'a'");
// Both literals, so we can compile immediately without having previously
// evaluated the expression.
assertCanCompile(expression);
assertThat(expression.getValue(String.class)).isEqualTo("a");
assertThat(getAst().getExitDescriptor()).isEqualTo("Ljava/lang/Object");
}
@Test // gh-19758
void elvisMiscellaneous() {
SpelParserConfiguration configuration = new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, null);