You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2013/08/22 16:28:32 UTC
svn commit: r1516460 -
/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Loader.java
Author: ggregory
Date: Thu Aug 22 14:28:32 2013
New Revision: 1516460
URL: http://svn.apache.org/r1516460
Log:
Sort members.
Modified:
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Loader.java
Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Loader.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Loader.java?rev=1516460&r1=1516459&r2=1516460&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Loader.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Loader.java Thu Aug 22 14:28:32 2013
@@ -28,12 +28,12 @@ import org.apache.logging.log4j.util.Pro
*/
public final class Loader {
- private static final String TSTR = "Caught Exception while in Loader.getResource. This may be innocuous.";
-
private static boolean ignoreTCL = false;
private static final Logger LOGGER = StatusLogger.getLogger();
+ private static final String TSTR = "Caught Exception while in Loader.getResource. This may be innocuous.";
+
static {
final String ignoreTCLProp = PropertiesUtil.getProperties().getStringProperty("log4j.ignoreTCL", null);
if (ignoreTCLProp != null) {
@@ -41,7 +41,30 @@ public final class Loader {
}
}
- private Loader() {
+ /**
+ * Returns the ClassLoader to use.
+ * @return the ClassLoader.
+ */
+ public static ClassLoader getClassLoader() {
+
+ return getClassLoader(Loader.class, null);
+ }
+
+ public static ClassLoader getClassLoader(final Class<?> class1, final Class<?> class2) {
+
+ ClassLoader loader1 = null;
+ try {
+ loader1 = getTCL();
+ } catch (final Exception ex) {
+ LOGGER.warn("Caught exception locating thread ClassLoader {}", ex.getMessage());
+ }
+ final ClassLoader loader2 = class1 == null ? null : class1.getClassLoader();
+ final ClassLoader loader3 = class2 == null ? null : class2.getClass().getClassLoader();
+
+ if (isChild(loader1, loader2)) {
+ return isChild(loader1, loader3) ? loader1 : loader3;
+ }
+ return isChild(loader2, loader3) ? loader2 : loader3;
}
/**
@@ -179,39 +202,22 @@ public final class Loader {
return ClassLoader.getSystemResourceAsStream(resource);
}
- /**
- * Load a Class by name.
- * @param className The class name.
- * @return The Class.
- * @throws ClassNotFoundException if the Class could not be found.
- */
- public static Class<?> loadClass(final String className) throws ClassNotFoundException {
- // Just call Class.forName(className) if we are instructed to ignore the TCL.
- if (ignoreTCL) {
- return Class.forName(className);
- }
- try {
- return getTCL().loadClass(className);
- } catch (final Throwable e) {
- return Class.forName(className);
- }
- }
-
- public static ClassLoader getClassLoader(final Class<?> class1, final Class<?> class2) {
-
- ClassLoader loader1 = null;
- try {
- loader1 = getTCL();
- } catch (final Exception ex) {
- LOGGER.warn("Caught exception locating thread ClassLoader {}", ex.getMessage());
+ private static ClassLoader getTCL() {
+ ClassLoader cl;
+ if (System.getSecurityManager() == null) {
+ cl = Thread.currentThread().getContextClassLoader();
+ } else {
+ cl = java.security.AccessController.doPrivileged(
+ new java.security.PrivilegedAction<ClassLoader>() {
+ @Override
+ public ClassLoader run() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ }
+ );
}
- final ClassLoader loader2 = class1 == null ? null : class1.getClassLoader();
- final ClassLoader loader3 = class2 == null ? null : class2.getClass().getClassLoader();
- if (isChild(loader1, loader2)) {
- return isChild(loader1, loader3) ? loader1 : loader3;
- }
- return isChild(loader2, loader3) ? loader2 : loader3;
+ return cl;
}
private static boolean isChild(final ClassLoader loader1, final ClassLoader loader2) {
@@ -226,29 +232,23 @@ public final class Loader {
}
/**
- * Returns the ClassLoader to use.
- * @return the ClassLoader.
+ * Load a Class by name.
+ * @param className The class name.
+ * @return The Class.
+ * @throws ClassNotFoundException if the Class could not be found.
*/
- public static ClassLoader getClassLoader() {
-
- return getClassLoader(Loader.class, null);
- }
-
- private static ClassLoader getTCL() {
- ClassLoader cl;
- if (System.getSecurityManager() == null) {
- cl = Thread.currentThread().getContextClassLoader();
- } else {
- cl = java.security.AccessController.doPrivileged(
- new java.security.PrivilegedAction<ClassLoader>() {
- @Override
- public ClassLoader run() {
- return Thread.currentThread().getContextClassLoader();
- }
- }
- );
+ public static Class<?> loadClass(final String className) throws ClassNotFoundException {
+ // Just call Class.forName(className) if we are instructed to ignore the TCL.
+ if (ignoreTCL) {
+ return Class.forName(className);
}
+ try {
+ return getTCL().loadClass(className);
+ } catch (final Throwable e) {
+ return Class.forName(className);
+ }
+ }
- return cl;
+ private Loader() {
}
}