Skip to content

Commit

Permalink
HV-1155 Initialize the ExpressionFactory properly in the ELContext
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Nov 21, 2016
1 parent 91563e0 commit 6f0da1d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Expand Up @@ -59,7 +59,7 @@ public ElTermResolver(Locale locale, ExpressionFactory expressionFactory) {
@Override
public String interpolate(MessageInterpolator.Context context, String expression) {
String resolvedExpression = expression;
SimpleELContext elContext = new SimpleELContext();
SimpleELContext elContext = new SimpleELContext( expressionFactory );
try {
ValueExpression valueExpression = bindContextValues( expression, context, elContext );
resolvedExpression = (String) valueExpression.getValue( elContext );
Expand Down
Expand Up @@ -7,11 +7,13 @@
package org.hibernate.validator.internal.engine.messageinterpolation.el;

import java.lang.reflect.Method;

import javax.el.ArrayELResolver;
import javax.el.BeanELResolver;
import javax.el.CompositeELResolver;
import javax.el.ELContext;
import javax.el.ELResolver;
import javax.el.ExpressionFactory;
import javax.el.ListELResolver;
import javax.el.MapELResolver;
import javax.el.ResourceBundleELResolver;
Expand All @@ -37,7 +39,14 @@ public class SimpleELContext extends ELContext {
private final VariableMapper variableMapper;
private final ELResolver resolver;

public SimpleELContext() {
public SimpleELContext(ExpressionFactory expressionFactory) {
// In javax.el.ELContext, the ExpressionFactory is extracted from the context map. If it is not found, it
// defaults to ELUtil.getExpressionFactory() which, if we provided the ExpressionFactory to the
// ResourceBundleMessageInterpolator, might not be the same, thus potentially instantiating another
// ExpressionFactory outside of the boundaries of the class loader safe loading mechanism of
// ResourceBundleMessageInterpolator.
putContext( ExpressionFactory.class, expressionFactory );

functions = new MapBasedFunctionMapper();
variableMapper = new MapBasedVariableMapper();
resolver = DEFAULT_RESOLVER;
Expand Down

0 comments on commit 6f0da1d

Please sign in to comment.