Merge pull request #150 from bohmber/MYFACES-4373-2.3.x
prefer secureRandom over random
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 3048efd..b14ed02 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 @@
import java.io.IOException;
import java.net.URL;
-import java.net.URLConnection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
@@ -240,11 +239,9 @@
if (System.currentTimeMillis() > target)
{
// 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 2085932..68867c9 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 @@
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.logging.Level;
@@ -332,12 +331,9 @@
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;
}
@@ -345,20 +341,6 @@
{
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 ef15a3b..0d7f726 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;
@@ -154,12 +152,9 @@
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;
}
@@ -167,25 +162,6 @@
{
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;
diff --git a/shared/src/main/java/org/apache/myfaces/shared/resource/ResourceLoaderUtils.java b/shared/src/main/java/org/apache/myfaces/shared/resource/ResourceLoaderUtils.java
index e993dd1..da3e099 100644
--- a/shared/src/main/java/org/apache/myfaces/shared/resource/ResourceLoaderUtils.java
+++ b/shared/src/main/java/org/apache/myfaces/shared/resource/ResourceLoaderUtils.java
@@ -19,6 +19,7 @@
package org.apache.myfaces.shared.resource;
import java.io.IOException;
+import java.io.InputStream;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLConnection;
@@ -75,53 +76,50 @@
return Long.valueOf(date.getTime());
}
- //Taken from trinidad URLUtils
public static long getResourceLastModified(URL url) throws IOException
{
- return getResourceLastModified(url.openConnection());
- }
+ long lastModified;
- //Taken from trinidad URLUtils
- 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 = jarFileUrl.openConnection();
-
- try
+ URLConnection connection = url.openConnection();
+ if (connection instanceof JarURLConnection)
{
- 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
{
- jarFileConnection.getInputStream().close();
+ is.close();
}
- catch (Exception exception)
+ catch (Exception e)
{
// Ignored
}
}
}
- else
- {
- modified = connection.getLastModified();
- }
- return modified;
+ return lastModified;
}
public static int getDepth(String path)