Skip to content

Commit 90867e7

Browse files
committed
Merge branch '6.1.x'
2 parents 5cac2ca + 528029a commit 90867e7

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

framework-docs/modules/ROOT/pages/core/expressions/evaluation.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ following kinds of expressions cannot be compiled.
518518
* Expressions relying on the conversion service
519519
* Expressions using custom resolvers or accessors
520520
* Expressions using overloaded operators
521+
* Expressions using array construction syntax
521522
* Expressions using selection or projection
522523

523524
Compilation of additional kinds of expressions may be supported in the future.

framework-docs/modules/ROOT/pages/core/expressions/language-ref/array-construction.adoc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Java::
1313
int[] numbers1 = (int[]) parser.parseExpression("new int[4]").getValue(context);
1414
1515
// Array with initializer
16-
int[] numbers2 = (int[]) parser.parseExpression("new int[]{1,2,3}").getValue(context);
16+
int[] numbers2 = (int[]) parser.parseExpression("new int[] {1, 2, 3}").getValue(context);
1717
1818
// Multi dimensional array
1919
int[][] numbers3 = (int[][]) parser.parseExpression("new int[4][5]").getValue(context);
@@ -26,14 +26,22 @@ Kotlin::
2626
val numbers1 = parser.parseExpression("new int[4]").getValue(context) as IntArray
2727
2828
// Array with initializer
29-
val numbers2 = parser.parseExpression("new int[]{1,2,3}").getValue(context) as IntArray
29+
val numbers2 = parser.parseExpression("new int[] {1, 2, 3}").getValue(context) as IntArray
3030
3131
// Multi dimensional array
3232
val numbers3 = parser.parseExpression("new int[4][5]").getValue(context) as Array<IntArray>
3333
----
3434
======
3535

36+
[NOTE]
37+
====
3638
You cannot currently supply an initializer when you construct a multi-dimensional array.
37-
38-
39-
39+
====
40+
41+
[CAUTION]
42+
====
43+
Any expression that constructs an array – for example, via `new int[4]` or
44+
`new int[] {1, 2, 3}` – cannot be compiled. See
45+
xref:core/expressions/evaluation.adoc#expressions-compiler-limitations[Compiler Limitations]
46+
for details.
47+
====

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
@@ -263,6 +263,12 @@ public void generateCode(MethodVisitor mv, CodeFlow cf) {
263263
}
264264
case "B" -> {
265265
mv.visitTypeInsn(CHECKCAST, "[B");
266+
// byte and boolean arrays are both loaded via BALOAD
267+
yield BALOAD;
268+
}
269+
case "Z" -> {
270+
mv.visitTypeInsn(CHECKCAST, "[Z");
271+
// byte and boolean arrays are both loaded via BALOAD
266272
yield BALOAD;
267273
}
268274
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
@@ -309,6 +309,18 @@ void indexIntoPrimitiveCharArray() {
309309
assertThat(getAst().getExitDescriptor()).isEqualTo("C");
310310
}
311311

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

0 commit comments

Comments
 (0)