-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
drekbour opened SPR-7209 and commented
Embedded SpEL expressions throw an NPE if looked-up property-placeholder variable is null.
Using the Elvis operator which is designed to deal with null:
@Value
("#{${property1}?:'default'}") private String property2;
This works fine if ${property1} evaluates to a non-null but provides the following if it is null.
Caused by: java.lang.NullPointerException
at org.springframework.expression.spel.ast.SpelNodeImpl.<init>(SpelNodeImpl.java:50)
at org.springframework.expression.spel.ast.Elvis.<init>(Elvis.java:33)
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatExpression(InternalSpelExpressionParser.java:143)
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.doParseExpression(InternalSpelExpressionParser.java:114)
at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:56)
at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:1)
at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpressions(TemplateAwareExpressionParser.java:128)
at org.springframework.expression.common.TemplateAwareExpressionParser.parseTemplate(TemplateAwareExpressionParser.java:74)
at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpression(TemplateAwareExpressionParser.java:64)
at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:119)
The same thing happens if you use a .property file with the following
property1=
property2=#{${property1}?:'default'}
Notes:
- This is a general SpEL problem, not anything specific to Elvis operator.
- Tested with Spring 3.0.2
- Mentioned on the forums previously: http://forum.springsource.org/showthread.php?t=82892
Affects: 3.0.2
Issue Links:
- Placeholder property: absent should be treated same as blank/empty [SPR-7294] #11953 Placeholder property: absent should be treated same as blank/empty
Referenced from: commits 101d838
1 votes, 2 watchers