Skip to content
Permalink
Browse files
BVAL-170: improve speed of message interpolation when the pattern cle…
…arly cannot contain an EL expression; thanks to Thomas Andraschko
  • Loading branch information
mbenson committed Feb 16, 2019
1 parent 0ac9e6f commit a0df5898fab16f7e84eff7b66cbebba7a2af7277
Showing 1 changed file with 18 additions and 17 deletions.
@@ -61,25 +61,26 @@ private EvaluationType(String trigger) {
@Override
public String interpolate(final String message, final Map<String, Object> annotationParameters,
final Object validatedValue) {
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();
if (message.contains("${") || 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();
}
} catch (final Exception e) {
// no-op
}
} catch (final Exception e) {
// no-op
}

return message;
}

0 comments on commit a0df589

Please sign in to comment.