From b1526a0a833666125c65fb78ad0ee79e880ec290 Mon Sep 17 00:00:00 2001 From: pizzi80 Date: Fri, 18 Oct 2024 12:32:35 +0200 Subject: [PATCH] VariableMapperWrapper: typo + generics + code clarification Signed-off-by: pizzi80 --- .../facelets/el/VariableMapperWrapper.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/impl/src/main/java/com/sun/faces/facelets/el/VariableMapperWrapper.java b/impl/src/main/java/com/sun/faces/facelets/el/VariableMapperWrapper.java index 57a06d2195..6e46aa3cf2 100644 --- a/impl/src/main/java/com/sun/faces/facelets/el/VariableMapperWrapper.java +++ b/impl/src/main/java/com/sun/faces/facelets/el/VariableMapperWrapper.java @@ -35,7 +35,7 @@ public class VariableMapperWrapper extends VariableMapper { private final VariableMapper target; - private Map vars; + private Map vars; /** * @param orig the original variable mapper to be wrapped @@ -46,22 +46,18 @@ public VariableMapperWrapper(VariableMapper orig) { } /** - * First tries to resolve agains the inner Map, then the wrapped ValueExpression. + * First tries to resolve against the inner Map, then the wrapped ValueExpression. * * @see jakarta.el.VariableMapper#resolveVariable(java.lang.String) */ @Override public ValueExpression resolveVariable(String variable) { - ValueExpression ve = null; try { - if (vars != null) { - ve = (ValueExpression) vars.get(variable); - } - if (ve == null) { - return target.resolveVariable(variable); - } - return ve; - } catch (StackOverflowError e) { + // note that vars may contain null values so we can't use vars.getOrDefault + final ValueExpression ve = (vars != null ? vars.get(variable) : null); + return ve != null ? ve : target.resolveVariable(variable); + } + catch (StackOverflowError e) { throw new ELException("Could not Resolve Variable [Overflow]: " + variable, e); } } @@ -74,8 +70,8 @@ public ValueExpression resolveVariable(String variable) { @Override public ValueExpression setVariable(String variable, ValueExpression expression) { if (vars == null) { - vars = new HashMap(); + vars = new HashMap<>(); } - return (ValueExpression) vars.put(variable, expression); + return vars.put(variable, expression); } }