Refactor creation of ExpressionFactory ELUtil doesn't require a factory for all operations whereas the ELManager does. Moving construction of the factory to the ELManager allows some limited unit testing of ELUtil without placing additional limits on how ELManager can be used.
diff --git a/api/src/main/java/jakarta/el/ELContext.java b/api/src/main/java/jakarta/el/ELContext.java index 3544eda..36cb770 100644 --- a/api/src/main/java/jakarta/el/ELContext.java +++ b/api/src/main/java/jakarta/el/ELContext.java
@@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2021 Oracle and/or its affiliates and others. + * Copyright (c) 1997, 2022 Oracle and/or its affiliates and others. * All rights reserved. * Copyright 2004 The Apache Software Foundation * @@ -439,7 +439,7 @@ ExpressionFactory exprFactory = (ExpressionFactory) getContext(ExpressionFactory.class); if (exprFactory == null) { - exprFactory = ELUtil.getExpressionFactory(); + exprFactory = ELManager.getExpressionFactory(); } return exprFactory.coerceToType(obj, targetType);
diff --git a/api/src/main/java/jakarta/el/ELManager.java b/api/src/main/java/jakarta/el/ELManager.java index 48fb6ca..b8c2c2f 100644 --- a/api/src/main/java/jakarta/el/ELManager.java +++ b/api/src/main/java/jakarta/el/ELManager.java
@@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2019 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2022 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -27,6 +27,8 @@ */ public class ELManager { + private static ExpressionFactory exprFactory = ExpressionFactory.newInstance(); + private StandardELContext elContext; /** @@ -35,7 +37,7 @@ * @return The ExpressionFactory */ public static ExpressionFactory getExpressionFactory() { - return ELUtil.getExpressionFactory(); + return exprFactory; } /**
diff --git a/api/src/main/java/jakarta/el/ELUtil.java b/api/src/main/java/jakarta/el/ELUtil.java index 8b8a8c4..266f87a 100644 --- a/api/src/main/java/jakarta/el/ELUtil.java +++ b/api/src/main/java/jakarta/el/ELUtil.java
@@ -53,8 +53,6 @@ private ELUtil() { } - public static ExpressionFactory exprFactory = ExpressionFactory.newInstance(); - /** * <p> * The <code>ThreadLocal</code> variable used to record the <code>jakarta.faces.context.FacesContext</code> instance for @@ -161,10 +159,6 @@ return result; } - static ExpressionFactory getExpressionFactory() { - return exprFactory; - } - static Constructor<?> findConstructor(Class<?> klass, Class<?>[] paramTypes, Object[] params) { String methodName = "<init>"; @@ -533,7 +527,7 @@ // TODO: This isn't pretty but it works. Significant refactoring would // be required to avoid the exception. try { - getExpressionFactory().coerceToType(src, target); + ELManager.getExpressionFactory().coerceToType(src, target); } catch (Exception e) { return false; }