Skip to content

Commit 2e98a8a

Browse files
committedMar 20, 2024·
Refine null-safety in spring-expression
See gh-32475
1 parent 592f236 commit 2e98a8a

File tree

8 files changed

+29
-14
lines changed

8 files changed

+29
-14
lines changed
 

Diff for: ‎spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ public TypeDescriptor getMapValueTypeDescriptor() {
463463
* @see #narrow(Object)
464464
*/
465465
@Nullable
466-
public TypeDescriptor getMapValueTypeDescriptor(Object mapValue) {
466+
public TypeDescriptor getMapValueTypeDescriptor(@Nullable Object mapValue) {
467467
return narrow(mapValue, getMapValueTypeDescriptor());
468468
}
469469

Diff for: ‎spring-expression/src/main/java/org/springframework/expression/EvaluationException.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.expression;
1818

19+
import org.springframework.lang.Nullable;
20+
1921
/**
2022
* Represent an exception that occurs during expression evaluation.
2123
*
@@ -38,7 +40,7 @@ public EvaluationException(String message) {
3840
* @param message description of the problem that occurred
3941
* @param cause the underlying cause of this exception
4042
*/
41-
public EvaluationException(String message, Throwable cause) {
43+
public EvaluationException(String message, @Nullable Throwable cause) {
4244
super(message,cause);
4345
}
4446

@@ -66,7 +68,7 @@ public EvaluationException(String expressionString, String message) {
6668
* @param message description of the problem that occurred
6769
* @param cause the underlying cause of this exception
6870
*/
69-
public EvaluationException(int position, String message, Throwable cause) {
71+
public EvaluationException(int position, String message, @Nullable Throwable cause) {
7072
super(position, message, cause);
7173
}
7274

Diff for: ‎spring-expression/src/main/java/org/springframework/expression/ExpressionException.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public ExpressionException(String message) {
4949
* @param message a descriptive message
5050
* @param cause the underlying cause of this exception
5151
*/
52-
public ExpressionException(String message, Throwable cause) {
52+
public ExpressionException(String message, @Nullable Throwable cause) {
5353
super(message, cause);
5454
this.expressionString = null;
5555
this.position = 0;
@@ -95,7 +95,7 @@ public ExpressionException(int position, String message) {
9595
* @param message a descriptive message
9696
* @param cause the underlying cause of this exception
9797
*/
98-
public ExpressionException(int position, String message, Throwable cause) {
98+
public ExpressionException(int position, String message, @Nullable Throwable cause) {
9999
super(message, cause);
100100
this.expressionString = null;
101101
this.position = position;
@@ -124,6 +124,7 @@ public final int getPosition() {
124124
* @see java.lang.Throwable#getMessage()
125125
*/
126126
@Override
127+
@Nullable
127128
public String getMessage() {
128129
return toDetailedString();
129130
}
@@ -132,6 +133,7 @@ public String getMessage() {
132133
* Return a detailed description of this exception, including the expression
133134
* String and position (if available) as well as the actual exception message.
134135
*/
136+
@Nullable
135137
public String toDetailedString() {
136138
if (this.expressionString != null) {
137139
StringBuilder output = new StringBuilder();
@@ -156,6 +158,7 @@ public String toDetailedString() {
156158
* that caused the failure.
157159
* @since 4.0
158160
*/
161+
@Nullable
159162
public String getSimpleMessage() {
160163
return super.getMessage();
161164
}

Diff for: ‎spring-expression/src/main/java/org/springframework/expression/ExpressionInvocationTargetException.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.expression;
1818

19+
import org.springframework.lang.Nullable;
20+
1921
/**
2022
* This exception wraps (as cause) a checked exception thrown by some method that SpEL
2123
* invokes. It differs from a SpelEvaluationException because this indicates the
@@ -28,7 +30,7 @@
2830
@SuppressWarnings("serial")
2931
public class ExpressionInvocationTargetException extends EvaluationException {
3032

31-
public ExpressionInvocationTargetException(int position, String message, Throwable cause) {
33+
public ExpressionInvocationTargetException(int position, String message, @Nullable Throwable cause) {
3234
super(position, message, cause);
3335
}
3436

@@ -40,7 +42,7 @@ public ExpressionInvocationTargetException(String expressionString, String messa
4042
super(expressionString, message);
4143
}
4244

43-
public ExpressionInvocationTargetException(String message, Throwable cause) {
45+
public ExpressionInvocationTargetException(String message, @Nullable Throwable cause) {
4446
super(message, cause);
4547
}
4648

Diff for: ‎spring-expression/src/main/java/org/springframework/expression/spel/InternalParseException.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.expression.spel;
1818

19+
import org.springframework.lang.Nullable;
20+
1921
/**
2022
* Wraps a real parse exception. This exception flows to the top parse method and then
2123
* the wrapped exception is thrown as the real problem.
@@ -26,11 +28,12 @@
2628
@SuppressWarnings("serial")
2729
public class InternalParseException extends RuntimeException {
2830

29-
public InternalParseException(SpelParseException cause) {
31+
public InternalParseException(@Nullable SpelParseException cause) {
3032
super(cause);
3133
}
3234

3335
@Override
36+
@Nullable
3437
public SpelParseException getCause() {
3538
return (SpelParseException) super.getCause();
3639
}

Diff for: ‎spring-expression/src/main/java/org/springframework/expression/spel/SpelEvaluationException.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.expression.spel;
1818

1919
import org.springframework.expression.EvaluationException;
20+
import org.springframework.lang.Nullable;
2021

2122
/**
2223
* Root exception for Spring EL related exceptions.
@@ -35,28 +36,29 @@ public class SpelEvaluationException extends EvaluationException {
3536

3637
private final SpelMessage message;
3738

39+
@Nullable
3840
private final Object[] inserts;
3941

4042

41-
public SpelEvaluationException(SpelMessage message, Object... inserts) {
43+
public SpelEvaluationException(SpelMessage message, @Nullable Object... inserts) {
4244
super(message.formatMessage(inserts));
4345
this.message = message;
4446
this.inserts = inserts;
4547
}
4648

47-
public SpelEvaluationException(int position, SpelMessage message, Object... inserts) {
49+
public SpelEvaluationException(int position, SpelMessage message, @Nullable Object... inserts) {
4850
super(position, message.formatMessage(inserts));
4951
this.message = message;
5052
this.inserts = inserts;
5153
}
5254

53-
public SpelEvaluationException(int position, Throwable cause, SpelMessage message, Object... inserts) {
55+
public SpelEvaluationException(int position, @Nullable Throwable cause, SpelMessage message, @Nullable Object... inserts) {
5456
super(position, message.formatMessage(inserts), cause);
5557
this.message = message;
5658
this.inserts = inserts;
5759
}
5860

59-
public SpelEvaluationException(Throwable cause, SpelMessage message, Object... inserts) {
61+
public SpelEvaluationException(@Nullable Throwable cause, SpelMessage message, @Nullable Object... inserts) {
6062
super(message.formatMessage(inserts), cause);
6163
this.message = message;
6264
this.inserts = inserts;
@@ -80,6 +82,7 @@ public SpelMessage getMessageCode() {
8082
/**
8183
* Return the message inserts.
8284
*/
85+
@Nullable
8386
public Object[] getInserts() {
8487
return this.inserts;
8588
}

Diff for: ‎spring-expression/src/main/java/org/springframework/expression/spel/SpelMessage.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.text.MessageFormat;
2020

21+
import org.springframework.lang.Nullable;
22+
2123
/**
2224
* Contains all the messages that can be produced by the Spring Expression Language.
2325
*
@@ -313,7 +315,7 @@ public enum SpelMessage {
313315
* @return a formatted message
314316
* @since 4.3.5
315317
*/
316-
public String formatMessage(Object... inserts) {
318+
public String formatMessage(@Nullable Object... inserts) {
317319
StringBuilder formattedMessage = new StringBuilder();
318320
formattedMessage.append("EL").append(this.code);
319321
if (this.kind == Kind.ERROR) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public abstract class SpelNodeImpl implements SpelNode, Opcodes {
7171
protected volatile String exitTypeDescriptor;
7272

7373

74-
public SpelNodeImpl(int startPos, int endPos, SpelNodeImpl... operands) {
74+
public SpelNodeImpl(int startPos, int endPos, @Nullable SpelNodeImpl... operands) {
7575
this.startPos = startPos;
7676
this.endPos = endPos;
7777
if (!ObjectUtils.isEmpty(operands)) {

0 commit comments

Comments
 (0)
Please sign in to comment.