Browse Source

TemplateAwareExpressionParser treats null as non-template ParserContext

Issue: SPR-15810
pull/1481/merge
Juergen Hoeller 7 years ago
parent
commit
af93503a09
  1. 17
      spring-expression/src/main/java/org/springframework/expression/ParserContext.java
  2. 25
      spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java

17
spring-expression/src/main/java/org/springframework/expression/ParserContext.java

@ -54,11 +54,16 @@ public interface ParserContext { @@ -54,11 +54,16 @@ public interface ParserContext {
/**
* The default ParserContext implementation that enables template expression parsing
* mode. The expression prefix is #{ and the expression suffix is }.
* The default ParserContext implementation that enables template expression
* parsing mode. The expression prefix is "#{" and the expression suffix is "}".
* @see #isTemplate()
*/
public static final ParserContext TEMPLATE_EXPRESSION = new ParserContext() {
ParserContext TEMPLATE_EXPRESSION = new ParserContext() {
@Override
public boolean isTemplate() {
return true;
}
@Override
public String getExpressionPrefix() {
@ -69,12 +74,6 @@ public interface ParserContext { @@ -69,12 +74,6 @@ public interface ParserContext {
public String getExpressionSuffix() {
return "}";
}
@Override
public boolean isTemplate() {
return true;
}
};
}

25
spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java

@ -37,33 +37,14 @@ import org.springframework.lang.Nullable; @@ -37,33 +37,14 @@ import org.springframework.lang.Nullable;
*/
public abstract class TemplateAwareExpressionParser implements ExpressionParser {
/**
* Default ParserContext instance for non-template expressions.
*/
private static final ParserContext NON_TEMPLATE_PARSER_CONTEXT = new ParserContext() {
@Override
public boolean isTemplate() {
return false;
}
@Override
public String getExpressionPrefix() {
return "";
}
@Override
public String getExpressionSuffix() {
return "";
}
};
@Override
public Expression parseExpression(String expressionString) throws ParseException {
return parseExpression(expressionString, NON_TEMPLATE_PARSER_CONTEXT);
return parseExpression(expressionString, null);
}
@Override
public Expression parseExpression(String expressionString, ParserContext context) throws ParseException {
if (context.isTemplate()) {
public Expression parseExpression(String expressionString, @Nullable ParserContext context) throws ParseException {
if (context != null && context.isTemplate()) {
return parseTemplate(expressionString, context);
}
else {

Loading…
Cancel
Save