You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/09/23 08:50:37 UTC

[1/2] logging-log4j2 git commit: LOG4J2-1010 bugfix in ThreadContextDataInjector.ForCopyOnWriteThreadContext: prevent potential UnsupportedOperationException when using async loggers and some loggers have properties configured and some don't

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 713f1a9ba -> 006706615


LOG4J2-1010 bugfix in ThreadContextDataInjector.ForCopyOnWriteThreadContext: prevent potential UnsupportedOperationException when using async loggers and some loggers have properties configured and some don't


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

Branch: refs/heads/master
Commit: 281ad99a011b1952c721e5f3063fc1dc639f1716
Parents: 713f1a9
Author: rpopma <rp...@apache.org>
Authored: Fri Sep 23 17:48:46 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Sep 23 17:48:46 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/impl/ThreadContextDataInjector.java | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/281ad99a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java
index d26324c..92144c4 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java
@@ -144,22 +144,25 @@ public class ThreadContextDataInjector  {
          * specified reusable StringMap.
          *
          * @param props list of configuration properties, may be {@code null}
-         * @param reusable a {@code StringMap} instance that may be reused to avoid creating temporary objects
+         * @param ignore a {@code StringMap} instance from the log event
          * @return a {@code StringMap} combining configuration properties with thread context data
          */
         @Override
-        public StringMap injectContextData(final List<Property> props, final StringMap reusable) {
+        public StringMap injectContextData(final List<Property> props, final StringMap ignore) {
             // If there are no configuration properties we want to just return the ThreadContext's StringMap:
             // it is a copy-on-write data structure so we are sure ThreadContext changes will not affect our copy.
             final StringMap immutableCopy = ThreadContextAccess.getThreadContextMap2().getReadOnlyContextData();
             if (props == null || props.isEmpty()) {
-                return immutableCopy;
+                return immutableCopy; // this will replace the LogEvent's context data with the returned instance
             }
             // However, if the list of Properties is non-empty we need to combine the properties and the ThreadContext
-            // data. In that case we will copy the key-value pairs into the specified reusable StringMap.
-            copyProperties(props, reusable);
-            reusable.putAll(immutableCopy);
-            return reusable;
+            // data. Note that we cannot reuse the specified StringMap: some Loggers may have properties defined
+            // and others not, so the LogEvent's context data may have been replaced with an immutable copy from
+            // the ThreadContext - this will throw an UnsupportedOperationException if we try to modify it.
+            final StringMap result = ContextDataFactory.createContextData();
+            copyProperties(props, result);
+            result.putAll(immutableCopy);
+            return result;
         }
 
         @Override


[2/2] logging-log4j2 git commit: LOG4J2-1010 renamed ThreadContextDataInjector inner implementation classes

Posted by rp...@apache.org.
LOG4J2-1010 renamed ThreadContextDataInjector inner implementation classes


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

Branch: refs/heads/master
Commit: 0067066157412a00621fdb87ff853ba91809ce18
Parents: 281ad99
Author: rpopma <rp...@apache.org>
Authored: Fri Sep 23 17:50:28 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Sep 23 17:50:28 2016 +0900

----------------------------------------------------------------------
 .../logging/log4j/core/impl/ContextDataInjectorFactory.java      | 4 ++--
 .../logging/log4j/core/impl/ThreadContextDataInjector.java       | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/00670661/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 4dcacbc..b0a6023 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
@@ -82,10 +82,10 @@ public class ContextDataInjectorFactory {
     private static ContextDataInjector createDefaultInjector() {
         final ThreadContextMap threadContextMap = ThreadContextAccess.getThreadContextMap();
         if (threadContextMap instanceof CopyOnWrite && threadContextMap instanceof ThreadContextMap2) {
-            return new ThreadContextDataInjector.ForCopyOnWriteMutableThreadContextMap();
+            return new ThreadContextDataInjector.ForCopyOnWriteThreadContextMap();
         }
         if (threadContextMap instanceof ThreadContextMap2) {
-            return new ThreadContextDataInjector.ForGarbageFreeMutableThreadContextMap();
+            return new ThreadContextDataInjector.ForGarbageFreeThreadContextMap();
         }
         return new ThreadContextDataInjector.ForDefaultThreadContextMap();
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/00670661/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java
index 92144c4..9920c06 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjector.java
@@ -102,7 +102,7 @@ public class ThreadContextDataInjector  {
      * <p>
      * This injector always puts key-value pairs into the specified reusable StringMap.
      */
-    public static class ForGarbageFreeMutableThreadContextMap implements ContextDataInjector {
+    public static class ForGarbageFreeThreadContextMap implements ContextDataInjector {
         /**
          * Puts key-value pairs from both the specified list of properties as well as the thread context into the
          * specified reusable StringMap.
@@ -137,7 +137,7 @@ public class ThreadContextDataInjector  {
      * structure. Otherwise the configuration properties are combined with the thread context key-value pairs into the
      * specified reusable StringMap.
      */
-    public static class ForCopyOnWriteMutableThreadContextMap implements ContextDataInjector {
+    public static class ForCopyOnWriteThreadContextMap implements ContextDataInjector {
         /**
          * If there are no configuration properties, this injector will return the thread context's internal data
          * structure. Otherwise the configuration properties are combined with the thread context key-value pairs into the