You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/09/22 01:09:15 UTC

[4/4] git commit: Update ConfigurationFactory.Factory to use TCCL.

Update ConfigurationFactory.Factory to use TCCL.

  - Prefer use of LoaderUtil.
  - Should help fix issues involving the Log4j ClassLoader and the
  application's ClassLoader being different (e.g., LOG4J2-795).


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/cb631914
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/cb631914
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/cb631914

Branch: refs/heads/master
Commit: cb631914cef1cd27a2bba38bb13977f02a1bb5be
Parents: 2fb7d67
Author: Matt Sicker <ma...@apache.org>
Authored: Sun Sep 21 18:04:18 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Sun Sep 21 18:04:18 2014 -0500

----------------------------------------------------------------------
 .../logging/log4j/core/config/ConfigurationFactory.java | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cb631914/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
index 37e3f80..e9c0d7b 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
@@ -42,7 +42,9 @@ import org.apache.logging.log4j.core.lookup.Interpolator;
 import org.apache.logging.log4j.core.lookup.StrSubstitutor;
 import org.apache.logging.log4j.core.util.FileUtils;
 import org.apache.logging.log4j.core.util.Loader;
+import org.apache.logging.log4j.core.util.ReflectionUtil;
 import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.LoaderUtil;
 import org.apache.logging.log4j.util.PropertiesUtil;
 
 /**
@@ -163,7 +165,7 @@ public abstract class ConfigurationFactory {
     @SuppressWarnings("unchecked")
     private static void addFactory(final Collection<ConfigurationFactory> list, final String factoryClass) {
         try {
-            addFactory(list, (Class<ConfigurationFactory>) Loader.loadClass(factoryClass));
+            addFactory(list, (Class<ConfigurationFactory>) LoaderUtil.loadClass(factoryClass));
         } catch (final Exception ex) {
             LOGGER.error("Unable to load class {}", factoryClass, ex);
         }
@@ -172,7 +174,7 @@ public abstract class ConfigurationFactory {
     private static void addFactory(final Collection<ConfigurationFactory> list,
                                    final Class<ConfigurationFactory> factoryClass) {
         try {
-            list.add(factoryClass.getConstructor().newInstance());
+            list.add(ReflectionUtil.instantiate(factoryClass));
         } catch (final Exception ex) {
             LOGGER.error("Unable to create instance of {}", factoryClass.getName(), ex);
         }
@@ -249,7 +251,7 @@ public abstract class ConfigurationFactory {
         final boolean isClassLoaderScheme = scheme != null && scheme.equals(CLASS_LOADER_SCHEME);
         final boolean isClassPathScheme = scheme != null && !isClassLoaderScheme && scheme.equals(CLASS_PATH_SCHEME);
         if (scheme == null || isClassLoaderScheme || isClassPathScheme) {
-            final ClassLoader loader = Loader.getThreadContextClassLoader();
+            final ClassLoader loader = LoaderUtil.getThreadContextClassLoader();
             String path;
             if (isClassLoaderScheme || isClassPathScheme) {
                 path = configLocation.getSchemeSpecificPart();
@@ -389,7 +391,7 @@ public abstract class ConfigurationFactory {
                         LOGGER.catching(Level.DEBUG, ex);
                     }
                     if (source == null) {
-                        final ClassLoader loader = this.getClass().getClassLoader();
+                        final ClassLoader loader = LoaderUtil.getThreadContextClassLoader();
                         source = getInputFromString(config, loader);
                     }
                     if (source != null) {
@@ -443,7 +445,7 @@ public abstract class ConfigurationFactory {
 
         private Configuration getConfiguration(final boolean isTest, final String name) {
             final boolean named = name != null && name.length() > 0;
-            final ClassLoader loader = this.getClass().getClassLoader();
+            final ClassLoader loader = LoaderUtil.getThreadContextClassLoader();
             for (final ConfigurationFactory factory : factories) {
                 String configName;
                 final String prefix = isTest ? TEST_PREFIX : DEFAULT_PREFIX;