Repository: logging-log4j2
Updated Branches:
  refs/heads/LOG4J2-1530 [created] f113499bc


LOG4J2-1530 LogEvent.getContextStack() should not return null


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

Branch: refs/heads/LOG4J2-1530
Commit: f113499bcff6f5014a838a9dfa68e720c654b261
Parents: 2f8236e
Author: Mikael Ståldal <mikael.stal...@magine.com>
Authored: Tue Sep 6 16:18:15 2016 +0200
Committer: Mikael Ståldal <mikael.stal...@magine.com>
Committed: Tue Sep 6 16:18:15 2016 +0200

----------------------------------------------------------------------
 .../logging/log4j/core/impl/ReusableLogEventFactory.java     | 2 +-
 .../logging/log4j/core/impl/ReusableLogEventFactoryTest.java | 8 ++++++++
 src/changes/changes.xml                                      | 3 +++
 3 files changed, 12 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f113499b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
index f396a4c..e6330bf 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
@@ -73,7 +73,7 @@ public class ReusableLogEventFactory implements 
LogEventFactory {
         result.setMessage(message);
         result.setThrown(t);
         result.setContextMap(Log4jLogEvent.createMap(properties));
-        result.setContextStack(ThreadContext.getDepth() == 0 ? null : 
ThreadContext.cloneStack());// mutable copy
+        result.setContextStack(ThreadContext.getDepth() == 0 ? 
ThreadContext.EMPTY_STACK : ThreadContext.cloneStack());// mutable copy
         result.setTimeMillis(message instanceof TimestampMessage
                 ? ((TimestampMessage) message).getTimestamp()
                 : CLOCK.currentTimeMillis());

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f113499b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactoryTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactoryTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactoryTest.java
index f163529..2863a43 100644
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactoryTest.java
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactoryTest.java
@@ -98,4 +98,12 @@ public class ReusableLogEventFactoryTest {
         assertEquals("tid", t2.getId(), event2[0].getThreadId());
     }
 
+    @Test
+    public void testCreateEventInitFieldsProperly() throws Exception {
+        final ReusableLogEventFactory factory = new ReusableLogEventFactory();
+        LogEvent event = callCreateEvent(factory, "logger", Level.INFO, new 
SimpleMessage("xyz"), null);
+        assertNotNull(event.getContextMap());
+        assertNotNull(event.getContextStack());
+    }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f113499b/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 861c446..1a06db4 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -24,6 +24,9 @@
   </properties>
   <body>
     <release version="2.7" date="2016-MM-DD" description="GA Release 2.7">
+      <action issue="LOG4J2-1530" dev="mikes" type="fix">
+        LogEvent.getContextStack() can return null.
+      </action>
       <action issue="LOG4J2-1518" dev="rpopma" type="fix" due-to="Leon Finker">
         Prevent deadlock in Async Loggers when queue is full and logged 
Object's toString() logs another message.
       </action>

Reply via email to