Merge branch '7.0.x'

This commit is contained in:
Sam Brannen
2026-04-12 17:17:27 +02:00
2 changed files with 23 additions and 0 deletions
@@ -103,6 +103,12 @@ public class Elvis extends SpelNodeImpl {
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
// If both elements are literals and the expression was not previously
// evaluated in interpreted mode, we may get here without the exit descriptor
// having been computed, so we must ensure the exit descriptor has been
// computed before proceeding.
computeExitTypeDescriptor();
Label elseTarget = new Label();
Label endOfIf = new Label();
@@ -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);