This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 31bce633bb5f90cf8d48074494e30254b939560d
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jan 27 11:14:15 2020 +0000

    Fix BZ 64097 Use ServiceLoader to load EL implementation
    
    https://bz.apache.org/bugzilla/show_bug.cgi?id=64097
---
 java/javax/el/ExpressionFactory.java | 42 ++++++++++--------------------------
 webapps/docs/changelog.xml           |  5 +++++
 2 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/java/javax/el/ExpressionFactory.java 
b/java/javax/el/ExpressionFactory.java
index 7bd20d6..9158e12 100644
--- a/java/javax/el/ExpressionFactory.java
+++ b/java/javax/el/ExpressionFactory.java
@@ -14,25 +14,23 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package javax.el;
 
-import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
 import java.lang.ref.WeakReference;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.Properties;
+import java.util.ServiceLoader;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
@@ -47,9 +45,6 @@ public abstract class ExpressionFactory {
     private static final boolean IS_SECURITY_ENABLED =
         (System.getSecurityManager() != null);
 
-    private static final String SERVICE_RESOURCE_NAME =
-        "META-INF/services/javax.el.ExpressionFactory";
-
     private static final String PROPERTY_NAME = "javax.el.ExpressionFactory";
 
     private static final String PROPERTY_FILE;
@@ -371,35 +366,20 @@ public abstract class ExpressionFactory {
     }
 
     private static String getClassNameServices(ClassLoader tccl) {
-        InputStream is = null;
 
-        if (tccl == null) {
-            is = ClassLoader.getSystemResourceAsStream(SERVICE_RESOURCE_NAME);
-        } else {
-            is = tccl.getResourceAsStream(SERVICE_RESOURCE_NAME);
+        ExpressionFactory result = null;
+
+        ServiceLoader<ExpressionFactory> serviceLoader = 
ServiceLoader.load(ExpressionFactory.class, tccl);
+        Iterator<ExpressionFactory> iter = serviceLoader.iterator();
+        while (result == null && iter.hasNext()) {
+            result = iter.next();
         }
 
-        if (is != null) {
-            String line = null;
-            try (InputStreamReader isr = new InputStreamReader(is, "UTF-8");
-                    BufferedReader br = new BufferedReader(isr)) {
-                line = br.readLine();
-                if (line != null && line.trim().length() > 0) {
-                    return line.trim();
-                }
-            } catch (UnsupportedEncodingException e) {
-                // Should never happen with UTF-8
-                // If it does - ignore & return null
-            } catch (IOException e) {
-                throw new ELException(Util.message(null, 
"expressionFactory.readFailed", SERVICE_RESOURCE_NAME), e);
-            } finally {
-                try {
-                    is.close();
-                } catch (IOException ioe) {/*Ignore*/}
-            }
+        if (result == null) {
+            return null;
         }
 
-        return null;
+        return result.getClass().getName();
     }
 
     private static String getClassNameJreDir() {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 9473e86..e774ffb 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -162,6 +162,11 @@
         performance optimisation aware of the new public class
         (<code>java.lang.Record</code>) added in Java 14. (markt)
       </fix>
+      <fix>
+        <bug>64097</bug>: Replace the faulty custom services lookup used for
+        <code>ExpressionFactory</code> implementations with
+        <code>ServiceLoader</code>. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Cluster">


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to