You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2021/01/18 14:04:31 UTC

[myfaces] branch 2.3-next updated: MYFACES-4375

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

tandraschko pushed a commit to branch 2.3-next
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/2.3-next by this push:
     new 15325d7  MYFACES-4375
15325d7 is described below

commit 15325d7892963e1b07beb6fb925a3345a1cc6665
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Mon Jan 18 15:04:22 2021 +0100

    MYFACES-4375
---
 .../myfaces/resource/ResourceLoaderUtils.java      | 60 ++++++++++------------
 .../facelets/impl/CacheELFaceletCacheImpl.java     |  4 +-
 .../view/facelets/impl/DefaultFaceletFactory.java  | 20 +-------
 .../view/facelets/impl/FaceletCacheImpl.java       | 26 +---------
 4 files changed, 31 insertions(+), 79 deletions(-)

diff --git a/impl/src/main/java/org/apache/myfaces/resource/ResourceLoaderUtils.java b/impl/src/main/java/org/apache/myfaces/resource/ResourceLoaderUtils.java
index c70286d..3d9168a 100644
--- a/impl/src/main/java/org/apache/myfaces/resource/ResourceLoaderUtils.java
+++ b/impl/src/main/java/org/apache/myfaces/resource/ResourceLoaderUtils.java
@@ -19,6 +19,7 @@
 package org.apache.myfaces.resource;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.JarURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
@@ -66,40 +67,39 @@ public class ResourceLoaderUtils
 
     public static long getResourceLastModified(URL url) throws IOException
     {
-        return getResourceLastModified(url.openConnection());
-    }
+        long lastModified;
 
-    public static long getResourceLastModified(URLConnection connection) throws IOException
-    {
-        long modified;
-        if (connection instanceof JarURLConnection)
+        InputStream is = null;
+        try
         {
-            // The following hack is required to work-around a JDK bug.
-            // getLastModified() on a JAR entry URL delegates to the actual JAR file
-            // rather than the JAR entry.
-            // This opens internally, and does not close, an input stream to the JAR
-            // file.
-            // In turn, you cannot close it by yourself, because it's internal.
-            // The work-around is to get the modification date of the JAR file
-            // manually,
-            // and then close that connection again.
-
-            URL jarFileUrl = ((JarURLConnection) connection).getJarFileURL();
-            URLConnection jarFileConnection = null;
-
-            try
+            URLConnection connection = url.openConnection();
+            if (connection instanceof JarURLConnection)
             {
-                jarFileConnection = jarFileUrl.openConnection();
-                modified = jarFileConnection.getLastModified();
+                // The following hack is required to work-around a JDK bug.
+                // getLastModified() on a JAR entry URL delegates to the actual JAR file rather than the JAR entry.
+                // This opens internally, and does not close, an input stream to the JAR file.
+                // In turn, you cannot close it by yourself, because it's internal.
+                // The work-around is to get the modification date of the JAR file manually,
+                // and then close that connection again.
+                JarURLConnection jarUrlConnection = (JarURLConnection) connection; 
+                URL jarFileUrl = jarUrlConnection.getJarFileURL(); 
+                URLConnection jarFileConnection = jarFileUrl.openConnection();
+                is = jarFileConnection.getInputStream();
+                lastModified = jarFileConnection.getLastModified(); 
             }
-            finally
+            else
+            {
+                is = connection.getInputStream();
+                lastModified = connection.getLastModified();
+            }
+        }
+        finally
+        {
+            if (is != null)
             {
                 try
                 {
-                    if (jarFileConnection != null)
-                    {
-                        jarFileConnection.getInputStream().close();
-                    }
+                    is.close();
                 }
                 catch (Exception e)
                 {
@@ -107,12 +107,8 @@ public class ResourceLoaderUtils
                 }
             }
         }
-        else
-        {
-            modified = connection.getLastModified();
-        }
 
-        return modified;
+        return lastModified;
     }
     
     public static int getDepth(String path)
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/impl/CacheELFaceletCacheImpl.java b/impl/src/main/java/org/apache/myfaces/view/facelets/impl/CacheELFaceletCacheImpl.java
index f96b8c7..f28baeb 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/impl/CacheELFaceletCacheImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/impl/CacheELFaceletCacheImpl.java
@@ -20,7 +20,6 @@ package org.apache.myfaces.view.facelets.impl;
 
 import java.io.IOException;
 import java.net.URL;
-import java.net.URLConnection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Map;
@@ -225,8 +224,7 @@ class CacheELFaceletCacheImpl extends AbstractFaceletCache<DefaultFacelet>
             // Should check for file modification
             try
             {
-                URLConnection conn = facelet.getSource().openConnection();
-                long lastModified = ResourceLoaderUtils.getResourceLastModified(conn);
+                long lastModified = ResourceLoaderUtils.getResourceLastModified(facelet.getSource());
 
                 return lastModified == 0 || lastModified > target;
             }
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletFactory.java b/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletFactory.java
index 53213e9..89cb0ae 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletFactory.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletFactory.java
@@ -21,7 +21,6 @@ package org.apache.myfaces.view.facelets.impl;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.net.URL;
-import java.net.URLConnection;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
@@ -301,12 +300,9 @@ public final class DefaultFaceletFactory extends FaceletFactory
         if (System.currentTimeMillis() > target)
         {
             // Should check for file modification
-
-            URLConnection conn = null;
             try
             {
-                conn = facelet.getSource().openConnection();
-                long lastModified = ResourceLoaderUtils.getResourceLastModified(conn);
+                long lastModified = ResourceLoaderUtils.getResourceLastModified(facelet.getSource());
 
                 return lastModified == 0 || lastModified > target;
             }
@@ -314,20 +310,6 @@ public final class DefaultFaceletFactory extends FaceletFactory
             {
                 throw new FaceletException("Error Checking Last Modified for " + facelet.getAlias(), e);
             }
-            finally
-            {
-                if (conn != null)
-                {
-                    try
-                    {
-                        conn.getInputStream().close();
-                    }
-                    catch (Exception e)
-                    {
-                        // Ignored
-                    }
-                }
-            }
         }
 
         return false;
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCacheImpl.java b/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCacheImpl.java
index edb84f2..4c115a7 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCacheImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCacheImpl.java
@@ -19,9 +19,7 @@
 package org.apache.myfaces.view.facelets.impl;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.URL;
-import java.net.URLConnection;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -151,12 +149,9 @@ class FaceletCacheImpl extends FaceletCache<DefaultFacelet>
         if (System.currentTimeMillis() > target)
         {
             // Should check for file modification
-
-            URLConnection conn = null;
             try
             {
-                conn = facelet.getSource().openConnection();
-                long lastModified = ResourceLoaderUtils.getResourceLastModified(conn);
+                long lastModified = ResourceLoaderUtils.getResourceLastModified(facelet.getSource());
 
                 return lastModified == 0 || lastModified > target;
             }
@@ -164,25 +159,6 @@ class FaceletCacheImpl extends FaceletCache<DefaultFacelet>
             {
                 throw new FaceletException("Error Checking Last Modified for " + facelet.getAlias(), e);
             }
-            finally
-            {
-                // finally close input stream when finished, if fails just continue.
-                if (conn != null)
-                {
-                    try 
-                    {
-                        InputStream is = conn.getInputStream();
-                        if (is != null)
-                        {
-                            is.close();
-                        }
-                    }
-                    catch (IOException e)
-                    {
-                        // Ignore 
-                    }
-                }
-            }
         }
 
         return false;