Source:
public String getMessage() { final SimpleContext ctx = new SimpleContext(); final SimpleContext singleElementContext = new SimpleContext(); if (record != null) { ResourceLineage lineage = new ResourceLineage(record.getLineage(), record); for (String name : lineage.getKeys()) { List<PersistentResource> values = lineage.getRecord(name); final ValueExpression expression; final ValueExpression singleElementExpression; if (values.size() == 1) { expression = EXPRESSION_FACTORY.createValueExpression(values.get(0).getObject(), Object.class); singleElementExpression = expression; } else { List<Object> objects = values.stream().map(PersistentResource::getObject) .collect(Collectors.toList()); expression = EXPRESSION_FACTORY.createValueExpression(objects, List.class); singleElementExpression = EXPRESSION_FACTORY.createValueExpression(values.get(values.size() - 1) .getObject(), Object.class); } ctx.setVariable(name, expression); singleElementContext.setVariable(name, singleElementExpression); } final User user = getUser(); if (user != null) { final Object opaqueUser = user.getOpaqueUser(); if (opaqueUser != null) { final ValueExpression opaqueUserValueExpression = EXPRESSION_FACTORY .createValueExpression( opaqueUser, Object.class ); ctx.setVariable("opaqueUser", opaqueUserValueExpression); singleElementContext.setVariable("opaqueUser", opaqueUserValueExpression); } } } Object[] results = new Object[expressions.length]; for (int idx = 0; idx < results.length; idx++) { String expressionText = expressions[idx]; final ValueExpression expression; final ValueExpression singleElementExpression; try { expression = EXPRESSION_FACTORY.createValueExpression(ctx, expressionText, Object.class); singleElementExpression = EXPRESSION_FACTORY.createValueExpression(singleElementContext, expressionText, Object.class); } catch (ELException e) { throw new InvalidSyntaxException(e); } Object result; try { result = singleElementExpression.getValue(singleElementContext); } catch (PropertyNotFoundException e) { result = expression.getValue(ctx); } results[idx] = result; } try { return MessageFormat.format(template, results); } catch (IllegalArgumentException e) { throw new InvalidSyntaxException(e); } }

Target:
public String getMessage() { final SimpleContext ctx = new SimpleContext(); final SimpleContext singleElementContext = new SimpleContext(); if (record != null) { ResourceLineage lineage = new ResourceLineage(record.getLineage(), record); for (String name : lineage.getKeys()) { List<PersistentResource> values = lineage.getRecord(name); final ValueExpression expression; final ValueExpression singleElementExpression; if (values.size() == 1) { expression = EXPRESSION_FACTORY.createValueExpression(values.get(0).getObject(), Object.class); singleElementExpression = expression; } else { List<Object> objects = values.stream().map(PersistentResource::getObject) .collect(Collectors.toList()); expression = EXPRESSION_FACTORY.createValueExpression(objects, List.class); singleElementExpression = EXPRESSION_FACTORY.createValueExpression(values.get(values.size() - 1) .getObject(), Object.class); } ctx.setVariable(name, expression); singleElementContext.setVariable(name, singleElementExpression); } final Object user = getUser(); if (user != null) { final ValueExpression opaqueUserValueExpression = EXPRESSION_FACTORY .createValueExpression( user, Object.class ); ctx.setVariable("opaqueUser", opaqueUserValueExpression); singleElementContext.setVariable("opaqueUser", opaqueUserValueExpression); } } Object[] results = new Object[expressions.length]; for (int idx = 0; idx < results.length; idx++) { String expressionText = expressions[idx]; final ValueExpression expression; final ValueExpression singleElementExpression; try { expression = EXPRESSION_FACTORY.createValueExpression(ctx, expressionText, Object.class); singleElementExpression = EXPRESSION_FACTORY.createValueExpression(singleElementContext, expressionText, Object.class); } catch (ELException e) { throw new InvalidSyntaxException(e); } Object result; try { result = singleElementExpression.getValue(singleElementContext); } catch (PropertyNotFoundException e) { result = expression.getValue(ctx); } results[idx] = result; } try { return MessageFormat.format(template, results); } catch (IllegalArgumentException e) { throw new InvalidSyntaxException(e); } }