Skip to content

Commit fea1464

Browse files
committed
Ensure SpEL can compile an expression indexing into a boolean array
Closes gh-32400
1 parent f6bc828 commit fea1464

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ public void generateCode(MethodVisitor mv, CodeFlow cf) {
245245
}
246246
case "B" -> {
247247
mv.visitTypeInsn(CHECKCAST, "[B");
248+
// byte and boolean arrays are both loaded via BALOAD
249+
yield BALOAD;
250+
}
251+
case "Z" -> {
252+
mv.visitTypeInsn(CHECKCAST, "[Z");
253+
// byte and boolean arrays are both loaded via BALOAD
248254
yield BALOAD;
249255
}
250256
case "C" -> {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,18 @@ void indexIntoPrimitiveCharArray() {
308308
assertThat(getAst().getExitDescriptor()).isEqualTo("C");
309309
}
310310

311+
@Test
312+
void indexIntoPrimitiveBooleanArray() {
313+
boolean[] booleans = { true, false };
314+
315+
expression = parser.parseExpression("[1]");
316+
317+
assertThat(expression.getValue(booleans)).isEqualTo(false);
318+
assertCanCompile(expression);
319+
assertThat(expression.getValue(booleans)).isEqualTo(false);
320+
assertThat(getAst().getExitDescriptor()).isEqualTo("Z");
321+
}
322+
311323
@Test
312324
void indexIntoStringArray() {
313325
String[] strings = { "a", "b", "c" };

0 commit comments

Comments
 (0)