@Test public void evaluateWhenVarIsNull() { String expression = "2*x + dummy.intValue"; Map<String, Object> vars = new HashMap<>(); vars.put("x", 2); vars.put("dummy", null); ExpressionEvaluator expressionEvaluator = new JexlExpressionEvaluator(); Object result = expressionEvaluator.evaluate( expression , vars); assertEquals("Incorrect evaluation when a var is null", "4", result.toString()); }
@Override public Object evaluate(String expression, Map<String, Object> context) { JexlContext jexlContext = new MapContext(context); try { Map<String, JexlExpression> expressionMap = expressionMapThreadLocal.get(); JexlExpression jexlExpression = expressionMap.get(expression); if (jexlExpression == null) { jexlExpression = getJexlEngine().createExpression(expression); expressionMap.put(expression, jexlExpression); } return jexlExpression.evaluate(jexlContext); } catch (Exception e) { throw new EvaluationException("An error occurred when evaluating expression " + expression, e); } }
JexlExpressionEvaluator implements ExpressionEvaluator { @Override public Object evaluate(String expression, Map<String, Object> context) { JexlContext jexlContext = new MapContext(context); try { Map<String, JexlExpression> expressionMap = expressionMapThreadLocal.get(); JexlExpression jexlExpression = expressionMap.get(expression); if (jexlExpression == null) { jexlExpression = getJexlEngine().createExpression(expression); expressionMap.put(expression, jexlExpression); } return jexlExpression.evaluate(jexlContext); } catch (Exception e) { throw new EvaluationException("An error occurred when evaluating expression " + expression, e); } } }
JexlExpressionEvaluator implements ExpressionEvaluator { @Override public Object evaluate(String expression, Map<String, Object> context) { JexlContext jexlContext = new MapContext(context); try { Map<String, JexlExpression> expressionMap = expressionMapThreadLocal.get(); JexlExpression jexlExpression = expressionMap.get(expression); if (jexlExpression == null) { jexlExpression = getJexlEngine().createExpression(expression); expressionMap.put(expression, jexlExpression); } return jexlExpression.evaluate(jexlContext); } catch (Exception e) { throw new EvaluationException("An error occurred when evaluating expression " + expression, e); } } JexlExpressionEvaluator();  JexlExpressionEvaluator(final boolean silent, final boolean strict);  JexlExpressionEvaluator(String expression);  JexlExpressionEvaluator(Map<String, Object> context);  JexlExpressionEvaluator(JexlContext jexlContext); }
JexlExpressionEvaluator implements ExpressionEvaluator { @Override public Object evaluate(String expression, Map<String, Object> context) { JexlContext jexlContext = new MapContext(context); try { Map<String, JexlExpression> expressionMap = expressionMapThreadLocal.get(); JexlExpression jexlExpression = expressionMap.get(expression); if (jexlExpression == null) { jexlExpression = getJexlEngine().createExpression(expression); expressionMap.put(expression, jexlExpression); } return jexlExpression.evaluate(jexlContext); } catch (Exception e) { throw new EvaluationException("An error occurred when evaluating expression " + expression, e); } } JexlExpressionEvaluator();  JexlExpressionEvaluator(final boolean silent, final boolean strict);  JexlExpressionEvaluator(String expression);  JexlExpressionEvaluator(Map<String, Object> context);  JexlExpressionEvaluator(JexlContext jexlContext); @Override Object evaluate(String expression, Map<String, Object> context); @Override Object evaluate(Map<String, Object> context); JexlExpression getJexlExpression(); void setJexlEngine(JexlEngine jexlEngine); JexlEngine getJexlEngine(); @Override String getExpression(); }
JexlExpressionEvaluator implements ExpressionEvaluator { @Override public Object evaluate(String expression, Map<String, Object> context) { JexlContext jexlContext = new MapContext(context); try { Map<String, JexlExpression> expressionMap = expressionMapThreadLocal.get(); JexlExpression jexlExpression = expressionMap.get(expression); if (jexlExpression == null) { jexlExpression = getJexlEngine().createExpression(expression); expressionMap.put(expression, jexlExpression); } return jexlExpression.evaluate(jexlContext); } catch (Exception e) { throw new EvaluationException("An error occurred when evaluating expression " + expression, e); } } JexlExpressionEvaluator();  JexlExpressionEvaluator(final boolean silent, final boolean strict);  JexlExpressionEvaluator(String expression);  JexlExpressionEvaluator(Map<String, Object> context);  JexlExpressionEvaluator(JexlContext jexlContext); @Override Object evaluate(String expression, Map<String, Object> context); @Override Object evaluate(Map<String, Object> context); JexlExpression getJexlExpression(); void setJexlEngine(JexlEngine jexlEngine); JexlEngine getJexlEngine(); @Override String getExpression();  }