commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skitch...@apache.org
Subject svn commit: r695208 - /commons/proper/logging/trunk/src/java/org/apache/commons/logging/LogFactory.java
Date Sun, 14 Sep 2008 12:26:03 GMT
Author: skitching
Date: Sun Sep 14 05:26:03 2008
New Revision: 695208

URL: http://svn.apache.org/viewvc?rev=695208&view=rev
Log:
Fix LOGGING-126: loading of commons-logging.properties file locks jars on windows.
Thanks to Philippe Mouawad for the report and patch.

Modified:
    commons/proper/logging/trunk/src/java/org/apache/commons/logging/LogFactory.java

Modified: commons/proper/logging/trunk/src/java/org/apache/commons/logging/LogFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/logging/trunk/src/java/org/apache/commons/logging/LogFactory.java?rev=695208&r1=695207&r2=695208&view=diff
==============================================================================
--- commons/proper/logging/trunk/src/java/org/apache/commons/logging/LogFactory.java (original)
+++ commons/proper/logging/trunk/src/java/org/apache/commons/logging/LogFactory.java Sun Sep
14 05:26:03 2008
@@ -27,6 +27,7 @@
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.URL;
+import java.net.URLConnection;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.Enumeration;
@@ -1420,18 +1421,36 @@
         PrivilegedAction action = 
             new PrivilegedAction() {
                 public Object run() {
+                    InputStream stream = null;
                     try {
-                        InputStream stream = url.openStream();
+                        // We must ensure that useCaches is set to false, as the
+                        // default behaviour of java is to cache file handles, and
+                        // this "locks" files, preventing hot-redeploy on windows.
+                        URLConnection connection = url.openConnection();
+                        connection.setDefaultUseCaches(false);
+                        stream = connection.getInputStream();
                         if (stream != null) {
                             Properties props = new Properties();
                             props.load(stream);
                             stream.close();
+                            stream = null;
                             return props;
                         }
                     } catch(IOException e) {
                         if (isDiagnosticsEnabled()) {
                             logDiagnostic("Unable to read URL " + url);
                         }
+                    } finally {
+                        if (stream != null) {
+                            try {
+                                stream.close();
+                            } catch(Throwable t) {
+                                // ignore exception; this should not happen
+                                if (isDiagnosticsEnabled()) {
+                                    logDiagnostic("Unable to close stream for URL " + url);
+                                }
+                            }
+                        }
                     }
 
                     return null;



Mime
View raw message