From beeeaba151e52395634bed2eb3654cb4c55ad56c Mon Sep 17 00:00:00 2001 From: Simon Kitching Date: Wed, 19 Jul 2006 23:31:00 +0000 Subject: [PATCH] Fix LOGGING-106 where JCL wouldn't start when run under a SecurityManager that refuses access to system properties. Also use an AccessController so that a signed JCL will work in an unsigned app; note that there appears to be other places where we are missing AccessControllers too. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@423654 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/logging/LogFactory.java | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/java/org/apache/commons/logging/LogFactory.java b/src/java/org/apache/commons/logging/LogFactory.java index 1fab5f6..8d92bee 100644 --- a/src/java/org/apache/commons/logging/LogFactory.java +++ b/src/java/org/apache/commons/logging/LogFactory.java @@ -316,8 +316,15 @@ public abstract class LogFactory { */ private static final Hashtable createFactoryStore() { Hashtable result = null; - String storeImplementationClass - = System.getProperty(HASHTABLE_IMPLEMENTATION_PROPERTY); + String storeImplementationClass; + try { + storeImplementationClass = System.getProperty(HASHTABLE_IMPLEMENTATION_PROPERTY); + } catch(SecurityException ex) { + // Permissions don't allow this to be accessed. Default to the "modern" + // weak hashtable implementation if it is available. + storeImplementationClass = null; + } + if (storeImplementationClass == null) { storeImplementationClass = WEAK_HASHTABLE_CLASSNAME; } @@ -1698,6 +1705,19 @@ public abstract class LogFactory { } } + // called from static class initialiser, ie when class is loaded + private static void initClass() { + // note: it's safe to call methods before initDiagnostics (though + // diagnostic output gets discarded). + thisClassLoader = getClassLoader(LogFactory.class); + initDiagnostics(); + logClassLoaderEnvironment(LogFactory.class); + factories = createFactoryStore(); + if (isDiagnosticsEnabled()) { + logDiagnostic("BOOTSTRAP COMPLETED"); + } + } + // ---------------------------------------------------------------------- // Static initialiser block to perform initialisation at class load time. // @@ -1718,13 +1738,12 @@ public abstract class LogFactory { // ---------------------------------------------------------------------- static { - // note: it's safe to call methods before initDiagnostics. - thisClassLoader = getClassLoader(LogFactory.class); - initDiagnostics(); - logClassLoaderEnvironment(LogFactory.class); - factories = createFactoryStore(); - if (isDiagnosticsEnabled()) { - logDiagnostic("BOOTSTRAP COMPLETED"); - } + AccessController.doPrivileged( + new PrivilegedAction() { + public Object run() { + initClass(); + return null; + } + }); } }