Skip to content

Commit be11e73

Browse files
committed
Refine null-safety in the spring-expression module
Closes gh-34156
1 parent 4747ab6 commit be11e73

File tree

5 files changed

+8
-9
lines changed

5 files changed

+8
-9
lines changed

spring-expression/src/main/java/org/springframework/expression/ExpressionException.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public String toDetailedString() {
153153
* that caused the failure.
154154
* @since 4.0
155155
*/
156-
@SuppressWarnings("NullAway")
156+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
157157
public String getSimpleMessage() {
158158
return super.getMessage();
159159
}

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

-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ private TypedValue executeFunctionViaMethod(ExpressionState state, Method method
174174
* @throws EvaluationException if there is any problem invoking the method
175175
* @since 6.1
176176
*/
177-
@SuppressWarnings("NullAway") // TODO Remove when NullAway 0.12.2 is released, see https://github.com/uber/NullAway/pull/1089
178177
private TypedValue executeFunctionViaMethodHandle(ExpressionState state, MethodHandle methodHandle) throws EvaluationException {
179178
Object[] functionArgs = getArguments(state);
180179
MethodType declaredParams = methodHandle.type();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ private DescriptorComparison(boolean areNumbers, boolean areCompatible, char com
351351
* @param rightActualDescriptor the dynamic/runtime right object descriptor
352352
* @return a DescriptorComparison object indicating the type of compatibility, if any
353353
*/
354-
@SuppressWarnings("NullAway")
354+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
355355
public static DescriptorComparison checkNumericCompatibility(
356356
@Nullable String leftDeclaredDescriptor, @Nullable String rightDeclaredDescriptor,
357357
@Nullable String leftActualDescriptor, @Nullable String rightActualDescriptor) {

spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ private void checkExpressionLength(String string) {
166166
// | (DEFAULT^ logicalOrExpression)
167167
// | (QMARK^ expression COLON! expression)
168168
// | (ELVIS^ expression))?;
169-
@SuppressWarnings("NullAway")
169+
@SuppressWarnings("NullAway") // Not null assertion performed in SpelNodeImpl constructor
170170
private @Nullable SpelNodeImpl eatExpression() {
171171
SpelNodeImpl expr = eatLogicalOrExpression();
172172
Token t = peekToken();
@@ -273,7 +273,7 @@ private void checkExpressionLength(String string) {
273273
}
274274

275275
//sumExpression: productExpression ( (PLUS^ | MINUS^) productExpression)*;
276-
@SuppressWarnings("NullAway")
276+
@SuppressWarnings("NullAway") // Not null assertion performed in SpelNodeImpl constructor
277277
private @Nullable SpelNodeImpl eatSumExpression() {
278278
SpelNodeImpl expr = eatProductExpression();
279279
while (peekToken(TokenKind.PLUS, TokenKind.MINUS, TokenKind.INC)) {
@@ -311,7 +311,7 @@ else if (t.kind == TokenKind.MOD) {
311311
}
312312

313313
// powerExpr : unaryExpression (POWER^ unaryExpression)? (INC || DEC) ;
314-
@SuppressWarnings("NullAway")
314+
@SuppressWarnings("NullAway") // Not null assertion performed in SpelNodeImpl constructor
315315
private @Nullable SpelNodeImpl eatPowerIncDecExpression() {
316316
SpelNodeImpl expr = eatUnaryExpression();
317317
if (peekToken(TokenKind.POWER)) {
@@ -331,7 +331,7 @@ else if (t.kind == TokenKind.MOD) {
331331
}
332332

333333
// unaryExpression: (PLUS^ | MINUS^ | BANG^ | INC^ | DEC^) unaryExpression | primaryExpression ;
334-
@SuppressWarnings("NullAway")
334+
@SuppressWarnings("NullAway") // Not null assertion performed in SpelNodeImpl constructor
335335
private @Nullable SpelNodeImpl eatUnaryExpression() {
336336
if (peekToken(TokenKind.NOT, TokenKind.PLUS, TokenKind.MINUS)) {
337337
Token t = takeToken();

spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public boolean canRead(EvaluationContext context, @Nullable Object target, Strin
154154
}
155155

156156
@Override
157-
@SuppressWarnings("NullAway")
157+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
158158
public TypedValue read(EvaluationContext context, @Nullable Object target, String name) throws AccessException {
159159
Assert.state(target != null, "Target must not be null");
160160
Class<?> type = (target instanceof Class<?> clazz ? clazz : target.getClass());
@@ -507,7 +507,7 @@ protected String getPropertyMethodSuffix(String propertyName) {
507507
* <p>Note: An optimized accessor is currently only usable for read attempts.
508508
* Do not call this method if you need a read-write accessor.
509509
*/
510-
@SuppressWarnings("NullAway")
510+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
511511
public PropertyAccessor createOptimalAccessor(EvaluationContext context, @Nullable Object target, String name) {
512512
// Don't be clever for arrays or a null target...
513513
if (target == null) {

0 commit comments

Comments
 (0)