Skip to content

Commit d2bd0d5

Browse files
committed
Retain null-safe syntax in AST representation of SpEL indexers
Prior to this commit, SpEL's CompoundExpression omitted the null-safe syntax in AST string representations of indexing operations. To address this, this commit implements isNullSafe() in Indexer. See gh-29847
1 parent 4d43317 commit d2bd0d5

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

+9
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ public Indexer(boolean nullSafe, int startPos, int endPos, SpelNodeImpl indexExp
127127
}
128128

129129

130+
/**
131+
* Does this node represent a null-safe index operation?
132+
* @since 6.2
133+
*/
134+
@Override
135+
public final boolean isNullSafe() {
136+
return this.nullSafe;
137+
}
138+
130139
@Override
131140
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
132141
return getValueRef(state).getValue();

Diff for: spring-expression/src/test/java/org/springframework/expression/spel/ParsingTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ void compoundExpressions() {
6060
parseCheck("property1?.property2?.methodOne()");
6161
parseCheck("property1?.methodOne('enigma')?.methodTwo(42)");
6262
parseCheck("property1?.methodOne()?.property2?.methodTwo()");
63-
parseCheck("property1[0]?.property2['key']?.methodTwo()");
64-
parseCheck("property1[0][1]?.property2['key'][42]?.methodTwo()");
63+
parseCheck("property1?.[0]?.property2?.['key']?.methodTwo()");
64+
parseCheck("property1?.[0]?.[1]?.property2?.['key']?.[42]?.methodTwo()");
6565
}
6666

6767
@Test

0 commit comments

Comments
 (0)