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 {
/** /**
* The default ParserContext implementation that enables template expression parsing * The default ParserContext implementation that enables template expression
* mode. The expression prefix is #{ and the expression suffix is }. * parsing mode. The expression prefix is "#{" and the expression suffix is "}".
* @see #isTemplate() * @see #isTemplate()
*/ */
public static final ParserContext TEMPLATE_EXPRESSION = new ParserContext() { ParserContext TEMPLATE_EXPRESSION = new ParserContext() {
@Override
public boolean isTemplate() {
return true;
}
@Override @Override
public String getExpressionPrefix() { public String getExpressionPrefix() {
@ -69,12 +74,6 @@ public interface ParserContext {
public String getExpressionSuffix() { public String getExpressionSuffix() {
return "}"; 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;
*/ */
public abstract class TemplateAwareExpressionParser implements ExpressionParser { 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 @Override
public Expression parseExpression(String expressionString) throws ParseException { public Expression parseExpression(String expressionString) throws ParseException {
return parseExpression(expressionString, NON_TEMPLATE_PARSER_CONTEXT); return parseExpression(expressionString, null);
} }
@Override @Override
public Expression parseExpression(String expressionString, ParserContext context) throws ParseException { public Expression parseExpression(String expressionString, @Nullable ParserContext context) throws ParseException {
if (context.isTemplate()) { if (context != null && context.isTemplate()) {
return parseTemplate(expressionString, context); return parseTemplate(expressionString, context);
} }
else { else {

Loading…
Cancel
Save