Document safe navigation semantics within compound expressions in SpEL
Closes gh-21827
This commit is contained in:
@@ -689,6 +689,25 @@ class SpelDocumentationTests extends AbstractExpressionTests {
|
||||
assertThat(inventor).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void nullSafeSelectFirstAndPropertyAccess() {
|
||||
IEEE society = new IEEE();
|
||||
StandardEvaluationContext context = new StandardEvaluationContext(society);
|
||||
String expression = "members?.^[nationality == 'Serbian']?.name"; // <1>
|
||||
|
||||
// evaluates to "Nikola Tesla"
|
||||
String name = parser.parseExpression(expression)
|
||||
.getValue(context, String.class);
|
||||
assertThat(name).isEqualTo("Nikola Tesla");
|
||||
|
||||
society.members = null;
|
||||
|
||||
// evaluates to null - does not throw a NullPointerException
|
||||
name = parser.parseExpression(expression)
|
||||
.getValue(context, String.class);
|
||||
assertThat(name).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void nullSafeSelectLast() {
|
||||
|
||||
Reference in New Issue
Block a user