Skip to content
Permalink
Browse files
BVAL-170 no need to test #{ in DefaultMessageInterpolator
  • Loading branch information
rmannibucau committed Feb 17, 2019
1 parent 28a176f commit 847d23e4f6ad313b2e7a8077631e79485e61be49
Showing 2 changed files with 14 additions and 16 deletions.
@@ -255,7 +255,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.3.1</version>
<version>2.4</version>
<executions>
<execution>
<goals>
@@ -62,22 +62,20 @@ private EvaluationType(String trigger) {
public String interpolate(final String message, final Map<String, Object> annotationParameters,
final Object validatedValue) {
// BVAL-170: simple pre-check to improve performance
if (message.contains("${") || message.contains("#{")) {
if (message.contains("${")) {
try {
if (EvaluationType.IMMEDIATE.regex.matcher(message).find()) {
final BValELContext context = new BValELContext();
final VariableMapper variables = context.getVariableMapper();
annotationParameters.forEach(
(k, v) -> variables.setVariable(k, expressionFactory.createValueExpression(v, Object.class)));

variables.setVariable("validatedValue",
expressionFactory.createValueExpression(validatedValue, Object.class));

// Java Bean Validation does not support EL expressions that look like JSP "deferred" expressions
return expressionFactory.createValueExpression(context,
EvaluationType.DEFERRED.regex.matcher(message).replaceAll("\\$0"), String.class).getValue(context)
.toString();
}
final BValELContext context = new BValELContext();
final VariableMapper variables = context.getVariableMapper();
annotationParameters.forEach(
(k, v) -> variables.setVariable(k, expressionFactory.createValueExpression(v, Object.class)));

variables.setVariable("validatedValue",
expressionFactory.createValueExpression(validatedValue, Object.class));

// Java Bean Validation does not support EL expressions that look like JSP "deferred" expressions
return expressionFactory.createValueExpression(context,
EvaluationType.DEFERRED.regex.matcher(message).replaceAll("\\$0"), String.class).getValue(context)
.toString();
} catch (final Exception e) {
// no-op
}

0 comments on commit 847d23e

Please sign in to comment.