LOG4J2-1660 use public method ThreadContext::getThreadContextMap instead of the 
(removed) ThreadContextAccess class.

Also rely on the default ThreadContextMap _not_ implementing 
ReadOnlyThreadContextMap rather than checking whether implementations implement 
ThreadContextMap2.


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

Branch: refs/heads/master
Commit: c3df21fe5b7b9541920bd7516c70e3d68fa186bc
Parents: 5039278
Author: rpopma <rpo...@apache.org>
Authored: Thu Nov 3 23:48:09 2016 +0900
Committer: rpopma <rpo...@apache.org>
Committed: Thu Nov 3 23:48:09 2016 +0900

----------------------------------------------------------------------
 .../core/impl/ContextDataInjectorFactory.java   | 22 +++++++++++---------
 1 file changed, 12 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c3df21fe/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ContextDataInjectorFactory.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ContextDataInjectorFactory.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ContextDataInjectorFactory.java
index b0a6023..fb1c330 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ContextDataInjectorFactory.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ContextDataInjectorFactory.java
@@ -16,16 +16,16 @@
  */
 package org.apache.logging.log4j.core.impl;
 
-import org.apache.logging.log4j.ThreadContextAccess;
+import org.apache.logging.log4j.ThreadContext;
 import org.apache.logging.log4j.core.ContextDataInjector;
 import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.util.ReadOnlyStringMap;
 import org.apache.logging.log4j.spi.CopyOnWrite;
-import org.apache.logging.log4j.spi.ThreadContextMap;
-import org.apache.logging.log4j.spi.ThreadContextMap2;
+import org.apache.logging.log4j.spi.DefaultThreadContextMap;
+import org.apache.logging.log4j.spi.ReadOnlyThreadContextMap;
 import org.apache.logging.log4j.status.StatusLogger;
 import org.apache.logging.log4j.util.LoaderUtil;
 import org.apache.logging.log4j.util.PropertiesUtil;
+import org.apache.logging.log4j.util.ReadOnlyStringMap;
 
 /**
  * Factory for ContextDataInjectors. Returns a new {@code ContextDataInjector} 
instance based on the value of system
@@ -80,13 +80,15 @@ public class ContextDataInjectorFactory {
     }
 
     private static ContextDataInjector createDefaultInjector() {
-        final ThreadContextMap threadContextMap = 
ThreadContextAccess.getThreadContextMap();
-        if (threadContextMap instanceof CopyOnWrite && threadContextMap 
instanceof ThreadContextMap2) {
-            return new 
ThreadContextDataInjector.ForCopyOnWriteThreadContextMap();
+        final ReadOnlyThreadContextMap threadContextMap = 
ThreadContext.getThreadContextMap();
+
+        // note: map may be null (if legacy custom ThreadContextMap was 
installed by user)
+        if (threadContextMap instanceof DefaultThreadContextMap || 
threadContextMap == null) {
+            return new ThreadContextDataInjector.ForDefaultThreadContextMap(); 
// for non StringMap-based context maps
         }
-        if (threadContextMap instanceof ThreadContextMap2) {
-            return new 
ThreadContextDataInjector.ForGarbageFreeThreadContextMap();
+        if (threadContextMap instanceof CopyOnWrite) {
+            return new 
ThreadContextDataInjector.ForCopyOnWriteThreadContextMap();
         }
-        return new ThreadContextDataInjector.ForDefaultThreadContextMap();
+        return new ThreadContextDataInjector.ForGarbageFreeThreadContextMap();
     }
 }

Reply via email to