logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattsic...@apache.org
Subject svn commit: r1611992 - /logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
Date Sun, 20 Jul 2014 01:49:26 GMT
Author: mattsicker
Date: Sun Jul 20 01:49:25 2014
New Revision: 1611992

URL: http://svn.apache.org/r1611992
Log:
Re-use LoaderUtil methods in Loader.

  - Remove duplicated code that was migrated to log4j-api.

Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java?rev=1611992&r1=1611991&r2=1611992&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
Sun Jul 20 01:49:25 2014
@@ -21,11 +21,10 @@ import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.ReflectPermission;
 import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.LoaderUtil;
 import org.apache.logging.log4j.util.PropertiesUtil;
 
 /**
@@ -39,9 +38,6 @@ public final class Loader {
 
     private static final String TSTR = "Caught Exception while in Loader.getResource. This
may be innocuous.";
 
-    private static final PrivilegedAction<ClassLoader> THREAD_CONTEXT_CLASS_LOADER_GETTER
=
-        new ThreadContextClassLoaderGetter();
-
     static {
         final String ignoreTCLProp = PropertiesUtil.getProperties().getStringProperty("log4j.ignoreTCL",
null);
         if (ignoreTCLProp != null) {
@@ -49,7 +45,6 @@ public final class Loader {
         }
         final SecurityManager sm = System.getSecurityManager();
         if (sm != null) {
-            sm.checkPermission(new RuntimePermission("getClassLoader"));
             sm.checkPermission(new RuntimePermission("getStackTrace"));
             sm.checkPermission(new ReflectPermission("suppressAccessChecks"));
         }
@@ -71,7 +66,7 @@ public final class Loader {
      * @return the TCCL.
      */
     public static ClassLoader getThreadContextClassLoader() {
-        return getTcl();
+        return LoaderUtil.getThreadContextClassLoader();
     }
 
     // TODO: this method could use some explanation
@@ -225,18 +220,7 @@ public final class Loader {
     }
 
     private static ClassLoader getTcl() {
-        return System.getSecurityManager() == null
-            ? THREAD_CONTEXT_CLASS_LOADER_GETTER.run()
-            : AccessController.doPrivileged(THREAD_CONTEXT_CLASS_LOADER_GETTER);
-    }
-
-    private static class ThreadContextClassLoaderGetter implements PrivilegedAction<ClassLoader>
{
-        @Override
-        public ClassLoader run() {
-            final ClassLoader cl = Thread.currentThread().getContextClassLoader();
-            // if the TCCL is null, that means we're using the system CL
-            return cl == null ? ClassLoader.getSystemClassLoader() : cl;
-        }
+        return LoaderUtil.getThreadContextClassLoader();
     }
 
     /**



Mime
View raw message