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 13:39:31 UTC
[myfaces] branch master updated: MYFACES-4375
This is an automated email from the ASF dual-hosted git repository.
tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/master by this push:
new 01769bf MYFACES-4375
01769bf is described below
commit 01769bf434be48bbad890d2412a479dafa1d510e
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Mon Jan 18 14:39:22 2021 +0100
MYFACES-4375
---
.../apache/myfaces/config/FacesConfigurator.java | 2 +-
.../myfaces/resource/ResourceLoaderUtils.java | 62 ++++++++++------------
.../facelets/impl/CacheELFaceletCacheImpl.java | 4 +-
.../view/facelets/impl/DefaultFaceletFactory.java | 20 +------
.../view/facelets/impl/FaceletCacheImpl.java | 26 +--------
5 files changed, 33 insertions(+), 81 deletions(-)
diff --git a/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java b/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
index 8fcbbd1..bdca6f0 100755
--- a/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
+++ b/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
@@ -277,7 +277,7 @@ public class FacesConfigurator
}
catch (IOException e)
{
- log.log(Level.SEVERE, "Could not read resource " + resource, e);
+ log.log(Level.SEVERE, "Could not read lastModified " + resource, e);
}
return 0;
}
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..31d68b8 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,14 +107,10 @@ public class ResourceLoaderUtils
}
}
}
- else
- {
- modified = connection.getLastModified();
- }
- return modified;
+ return lastModified;
}
-
+
public static int getDepth(String path)
{
int depth = 0;
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 90ec406..fa1fafb 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 980cda8..fe0e321 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 6e09097..d8da986 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;