diff --git a/spring-expression/src/main/java/org/springframework/expression/ParserContext.java b/spring-expression/src/main/java/org/springframework/expression/ParserContext.java index b41a6494a3..2554e7afad 100644 --- a/spring-expression/src/main/java/org/springframework/expression/ParserContext.java +++ b/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 - * 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 { public String getExpressionSuffix() { return "}"; } - - @Override - public boolean isTemplate() { - return true; - } - }; } diff --git a/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java b/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java index 774f83ab12..0e7e1e9139 100644 --- a/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java +++ b/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 { - /** - * 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 {