Skip to content

Commit 89a3d64

Browse files
committed
Reintroduce support for null SpEL expressions
Closes gh-30464
1 parent a8bc099 commit 89a3d64

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ protected SpelExpression doParseExpression(String expressionString, @Nullable Pa
158158
}
159159

160160
private void checkExpressionLength(String string) {
161-
if (string.length() > MAX_EXPRESSION_LENGTH) {
161+
if (string != null && string.length() > MAX_EXPRESSION_LENGTH) {
162162
throw new SpelEvaluationException(SpelMessage.MAX_EXPRESSION_LENGTH_EXCEEDED, MAX_EXPRESSION_LENGTH);
163163
}
164164
}

spring-expression/src/test/java/org/springframework/expression/spel/standard/SpelParserTests.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,9 @@
2121
import org.junit.jupiter.api.Test;
2222

2323
import org.springframework.expression.EvaluationContext;
24+
import org.springframework.expression.Expression;
2425
import org.springframework.expression.ExpressionException;
26+
import org.springframework.expression.ExpressionParser;
2527
import org.springframework.expression.spel.SpelMessage;
2628
import org.springframework.expression.spel.SpelNode;
2729
import org.springframework.expression.spel.SpelParseException;
@@ -35,9 +37,19 @@
3537
/**
3638
* @author Andy Clement
3739
* @author Juergen Hoeller
40+
* @author Sam Brannen
3841
*/
3942
public class SpelParserTests {
4043

44+
@Test // gh-30464
45+
public void nullExpression() {
46+
ExpressionParser parser = new SpelExpressionParser();
47+
String expression = null;
48+
Expression expr = parser.parseExpression(expression);
49+
Object result = expr.getValue();
50+
assertThat(result).isNull();
51+
}
52+
4153
@Test
4254
public void theMostBasic() {
4355
SpelExpressionParser parser = new SpelExpressionParser();

0 commit comments

Comments
 (0)