Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-7209

SpEL: Elvis operator throwing NPE in case of an empty base expression

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 3.0.2
    • Fix Version/s: 3.0.3
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      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:

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                aclement Andy Clement
                Reporter:
                drekbour drekbour
                Last updater:
                Trevor Marshall
              • Votes:
                1 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  7 years, 50 weeks ago