Skip to content

Commit

Permalink
Retain null-safe syntax in AST representation of SpEL indexers
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sbrannen committed Mar 23, 2024
1 parent 4d43317 commit d2bd0d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ public Indexer(boolean nullSafe, int startPos, int endPos, SpelNodeImpl indexExp
}


/**
* Does this node represent a null-safe index operation?
* @since 6.2
*/
@Override
public final boolean isNullSafe() {
return this.nullSafe;
}

@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
return getValueRef(state).getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ void compoundExpressions() {
parseCheck("property1?.property2?.methodOne()");
parseCheck("property1?.methodOne('enigma')?.methodTwo(42)");
parseCheck("property1?.methodOne()?.property2?.methodTwo()");
parseCheck("property1[0]?.property2['key']?.methodTwo()");
parseCheck("property1[0][1]?.property2['key'][42]?.methodTwo()");
parseCheck("property1?.[0]?.property2?.['key']?.methodTwo()");
parseCheck("property1?.[0]?.[1]?.property2?.['key']?.[42]?.methodTwo()");
}

@Test
Expand Down

0 comments on commit d2bd0d5

Please sign in to comment.