1
0

Fix LOGGING-126: loading of commons-logging.properties file locks jars on windows.

Thanks to Philippe Mouawad for the report and patch.


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/logging/trunk@695208 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Simon Kitching
2008-09-14 12:26:03 +00:00
parent 78475d429b
commit 12f0edf24b

View File

@@ -27,6 +27,7 @@ import java.io.PrintStream;
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 @@ public abstract class LogFactory {
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;