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 2015/06/02 20:01:48 UTC

logging-log4j2 git commit: [LOG4J2-1037] Backward compatibility issue in log4j-1.2-api NDC pop() and peek().

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 1445c7647 -> d865e43df


[LOG4J2-1037] Backward compatibility issue in log4j-1.2-api NDC pop()
and peek().

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

Branch: refs/heads/master
Commit: d865e43df0bc9558f01b494b970a82fb60178a95
Parents: 1445c76
Author: Gary Gregory <ga...@gmail.com>
Authored: Tue Jun 2 11:01:39 2015 -0700
Committer: Gary Gregory <ga...@gmail.com>
Committed: Tue Jun 2 11:01:39 2015 -0700

----------------------------------------------------------------------
 .../src/test/java/org/apache/log4j/NDCTest.java | 36 ++++++++++++++++++++
 .../log4j/spi/DefaultThreadContextStack.java    |  6 ++--
 src/changes/changes.xml                         |  3 ++
 3 files changed, 42 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d865e43d/log4j-1.2-api/src/test/java/org/apache/log4j/NDCTest.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/NDCTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/NDCTest.java
new file mode 100644
index 0000000..c8baf0f
--- /dev/null
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/NDCTest.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.log4j;
+
+import org.apache.logging.log4j.util.Strings;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class NDCTest {
+
+    @Test
+    public void testPopEmpty() {
+        NDC.clear();
+        Assert.assertEquals(Strings.EMPTY, NDC.pop());
+    }
+
+    @Test
+    public void testPeekEmpty() {
+        NDC.clear();
+        Assert.assertEquals(Strings.EMPTY, NDC.peek());
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d865e43d/log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextStack.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextStack.java b/log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextStack.java
index 9ec2e68..12229ca 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextStack.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextStack.java
@@ -20,7 +20,6 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
-import java.util.NoSuchElementException;
 
 import org.apache.logging.log4j.ThreadContext.ContextStack;
 import org.apache.logging.log4j.util.Strings;
@@ -170,7 +169,7 @@ public class DefaultThreadContextStack implements ThreadContextStack {
     public String peek() {
         final MutableThreadContextStack values = stack.get();
         if (values == null || values.size() == 0) {
-            return null;
+            return Strings.EMPTY;
         }
         return values.peek();
     }
@@ -182,7 +181,8 @@ public class DefaultThreadContextStack implements ThreadContextStack {
         }
         final MutableThreadContextStack values = stack.get();
         if (values == null || values.size() == 0) {
-            throw new NoSuchElementException("The ThreadContext stack is empty");
+            // Like version 1.2
+            return Strings.EMPTY;
         }
         final MutableThreadContextStack copy = (MutableThreadContextStack) values.copy();
         final String result = copy.pop();

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d865e43d/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1f334ca..4a85231 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -30,6 +30,9 @@
       <action issue="LOG4J2-1015" dev="ggregory" type="add">
         Add a way to route messages based on the %marker in Layout for RoutingAppender.
       </action>
+      <action issue="LOG4J2-1037" dev="ggregory" type="fix" due-to="Marc Dergacz">
+        Backward compatibility issue in log4j-1.2-api NDC pop() and peek().
+      </action>
       <action issue="LOG4J2-1033" dev="ggregory" type="fix" due-to="Mikael Ståldal">
         SimpleLogger creates unnecessary Map objects by calling ThreadContext.getContext() instead of getImmutableContext().
       </action>