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 2016/03/03 04:08:40 UTC

[1/3] logging-log4j2 git commit: LOG4J2-1227 Test if the event is null before using it, to avoid NullPointerException. Add some unit tests. Submitted by: Olivier Lemasle

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 60d1ccd93 -> a57fc35b9


LOG4J2-1227
    Test if the event is null before using it, to avoid NullPointerException.
    Add some unit tests.
    Submitted by: Olivier Lemasle <o....@gmail.com>


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

Branch: refs/heads/master
Commit: 33ee4bfd0aa1f58a705771222132a42d1dfb328c
Parents: 13b0dd8
Author: Olivier Lemasle <ol...@apalia.net>
Authored: Mon Dec 21 16:53:36 2015 +0100
Committer: Olivier Lemasle <ol...@apalia.net>
Committed: Mon Dec 21 16:53:36 2015 +0100

----------------------------------------------------------------------
 .../logging/log4j/core/lookup/MapLookup.java    |  2 +-
 .../log4j/core/lookup/MapLookupTest.java        | 25 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33ee4bfd/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java
index c369a0b..c00645e 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java
@@ -118,7 +118,7 @@ public class MapLookup implements StrLookup {
 
     @Override
     public String lookup(final LogEvent event, final String key) {
-        final boolean isMapMessage = event.getMessage() instanceof MapMessage;
+        final boolean isMapMessage = event != null && event.getMessage() instanceof MapMessage;
         if (map == null && !isMapMessage) {
             return null;
         }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33ee4bfd/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
index be550e3..5f26d15 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
@@ -20,6 +20,9 @@ import static org.junit.Assert.assertEquals;
 
 import java.util.HashMap;
 
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.message.MapMessage;
 import org.junit.Test;
 
 /**
@@ -64,4 +67,26 @@ public class MapLookupTest {
         assertEquals(null, lookup.lookup("foo.txt"));
     }
 
+    @Test
+    public void testEventMapMessage() {
+      final HashMap<String, String> map = new HashMap<>();
+      map.put("A", "B");
+      final HashMap<String, String> eventMap = new HashMap<>();
+      eventMap.put("A1", "B1");
+      final MapMessage message = new MapMessage(eventMap);
+      final LogEvent event = Log4jLogEvent.newBuilder()
+                .setMessage(message)
+                .build();
+      final MapLookup lookup = new MapLookup(map);
+      assertEquals("B", lookup.lookup(event, "A"));
+      assertEquals("B1", lookup.lookup(event, "A"));
+    }
+
+    @Test
+    public void testNullEvent() {
+      final HashMap<String, String> map = new HashMap<>();
+      map.put("A", "B");
+      final MapLookup lookup = new MapLookup(map);
+      assertEquals("B", lookup.lookup(null, "A"));
+    }
 }


Re: [3/3] logging-log4j2 git commit: Add changelog entry for LOG4J2-1227.

Posted by Matt Sicker <bo...@gmail.com>.
Got it.

On 2 March 2016 at 22:17, Remko Popma <re...@gmail.com> wrote:

> Typo: "is the event" -> "if the event"
>
>
> On Thursday, 3 March 2016, <ma...@apache.org> wrote:
>
>> Add changelog entry for LOG4J2-1227.
>>
>> This closes #20
>>
>>
>> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>> Commit:
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/a57fc35b
>> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/a57fc35b
>> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/a57fc35b
>>
>> Branch: refs/heads/master
>> Commit: a57fc35b97bda2fec4715040f58f048288f5a2b5
>> Parents: 6362a38
>> Author: Matt Sicker <bo...@gmail.com>
>> Authored: Wed Mar 2 21:08:37 2016 -0600
>> Committer: Matt Sicker <bo...@gmail.com>
>> Committed: Wed Mar 2 21:08:37 2016 -0600
>>
>> ----------------------------------------------------------------------
>>  src/changes/changes.xml | 3 +++
>>  1 file changed, 3 insertions(+)
>> ----------------------------------------------------------------------
>>
>>
>>
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a57fc35b/src/changes/changes.xml
>> ----------------------------------------------------------------------
>> diff --git a/src/changes/changes.xml b/src/changes/changes.xml
>> index 646a41f..80a67f7 100644
>> --- a/src/changes/changes.xml
>> +++ b/src/changes/changes.xml
>> @@ -184,6 +184,9 @@
>>        <action issue="LOG4J2-1252" dev="mattsicker" type="add">
>>          JeroMqAppender should support layouts.
>>        </action>
>> +      <action issue="LOG4J2-1227" dev="mattsicker" type="fix"
>> due-to="Olivier Lemasle">
>> +        NullPointerException in MapLookup.lookup is the event is null.
>> +      </action>
>>      </release>
>>      <release version="2.5" date="2015-12-06" description="GA Release
>> 2.5">
>>        <action issue="LOG4J2-324" dev="rpopma" type="fix">
>>
>>


-- 
Matt Sicker <bo...@gmail.com>

Re: [3/3] logging-log4j2 git commit: Add changelog entry for LOG4J2-1227.

Posted by Remko Popma <re...@gmail.com>.
Typo: "is the event" -> "if the event"


On Thursday, 3 March 2016, <ma...@apache.org> wrote:

> Add changelog entry for LOG4J2-1227.
>
> This closes #20
>
>
> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
> Commit:
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/a57fc35b
> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/a57fc35b
> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/a57fc35b
>
> Branch: refs/heads/master
> Commit: a57fc35b97bda2fec4715040f58f048288f5a2b5
> Parents: 6362a38
> Author: Matt Sicker <boards@gmail.com <javascript:;>>
> Authored: Wed Mar 2 21:08:37 2016 -0600
> Committer: Matt Sicker <boards@gmail.com <javascript:;>>
> Committed: Wed Mar 2 21:08:37 2016 -0600
>
> ----------------------------------------------------------------------
>  src/changes/changes.xml | 3 +++
>  1 file changed, 3 insertions(+)
> ----------------------------------------------------------------------
>
>
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a57fc35b/src/changes/changes.xml
> ----------------------------------------------------------------------
> diff --git a/src/changes/changes.xml b/src/changes/changes.xml
> index 646a41f..80a67f7 100644
> --- a/src/changes/changes.xml
> +++ b/src/changes/changes.xml
> @@ -184,6 +184,9 @@
>        <action issue="LOG4J2-1252" dev="mattsicker" type="add">
>          JeroMqAppender should support layouts.
>        </action>
> +      <action issue="LOG4J2-1227" dev="mattsicker" type="fix"
> due-to="Olivier Lemasle">
> +        NullPointerException in MapLookup.lookup is the event is null.
> +      </action>
>      </release>
>      <release version="2.5" date="2015-12-06" description="GA Release 2.5">
>        <action issue="LOG4J2-324" dev="rpopma" type="fix">
>
>

[3/3] logging-log4j2 git commit: Add changelog entry for LOG4J2-1227.

Posted by ma...@apache.org.
Add changelog entry for LOG4J2-1227.

This closes #20


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

Branch: refs/heads/master
Commit: a57fc35b97bda2fec4715040f58f048288f5a2b5
Parents: 6362a38
Author: Matt Sicker <bo...@gmail.com>
Authored: Wed Mar 2 21:08:37 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Wed Mar 2 21:08:37 2016 -0600

----------------------------------------------------------------------
 src/changes/changes.xml | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a57fc35b/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 646a41f..80a67f7 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -184,6 +184,9 @@
       <action issue="LOG4J2-1252" dev="mattsicker" type="add">
         JeroMqAppender should support layouts.
       </action>
+      <action issue="LOG4J2-1227" dev="mattsicker" type="fix" due-to="Olivier Lemasle">
+        NullPointerException in MapLookup.lookup is the event is null.
+      </action>
     </release>
     <release version="2.5" date="2015-12-06" description="GA Release 2.5">
       <action issue="LOG4J2-324" dev="rpopma" type="fix">


[2/3] logging-log4j2 git commit: Merge branch 'LOG4J2-1227' of https://github.com/olivierlemasle/logging-log4j2

Posted by ma...@apache.org.
Merge branch 'LOG4J2-1227' of https://github.com/olivierlemasle/logging-log4j2


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

Branch: refs/heads/master
Commit: 6362a382cb808748459d22b2dc89b431a6345be4
Parents: 60d1ccd 33ee4bf
Author: Matt Sicker <bo...@gmail.com>
Authored: Wed Mar 2 21:05:27 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Wed Mar 2 21:05:27 2016 -0600

----------------------------------------------------------------------
 .../logging/log4j/core/lookup/MapLookup.java    |  2 +-
 .../log4j/core/lookup/MapLookupTest.java        | 25 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------



Re: [1/3] logging-log4j2 git commit: LOG4J2-1227 Test if the event is null before using it, to avoid NullPointerException. Add some unit tests. Submitted by: Olivier Lemasle

Posted by Matt Sicker <bo...@gmail.com>.
Sorry, the pull request that caused this had a follow-up that I just merged
in today.

On 3 March 2016 at 10:21, Ralph Goers <ra...@dslextreme.com> wrote:

> This test is still failing.
>
> Ralph
>
> > On Mar 2, 2016, at 10:34 PM, Ralph Goers <ra...@dslextreme.com>
> wrote:
> >
> > It appears that the newly added testEventMapMessage is not working.
> >
> > Ralph
> >
> >> On Mar 2, 2016, at 8:08 PM, mattsicker@apache.org wrote:
> >>
> >> Repository: logging-log4j2
> >> Updated Branches:
> >> refs/heads/master 60d1ccd93 -> a57fc35b9
> >>
> >>
> >> LOG4J2-1227
> >>   Test if the event is null before using it, to avoid
> NullPointerException.
> >>   Add some unit tests.
> >>   Submitted by: Olivier Lemasle <o....@gmail.com>
> >>
> >>
> >> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
> >> Commit:
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/33ee4bfd
> >> Tree:
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/33ee4bfd
> >> Diff:
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/33ee4bfd
> >>
> >> Branch: refs/heads/master
> >> Commit: 33ee4bfd0aa1f58a705771222132a42d1dfb328c
> >> Parents: 13b0dd8
> >> Author: Olivier Lemasle <ol...@apalia.net>
> >> Authored: Mon Dec 21 16:53:36 2015 +0100
> >> Committer: Olivier Lemasle <ol...@apalia.net>
> >> Committed: Mon Dec 21 16:53:36 2015 +0100
> >>
> >> ----------------------------------------------------------------------
> >> .../logging/log4j/core/lookup/MapLookup.java    |  2 +-
> >> .../log4j/core/lookup/MapLookupTest.java        | 25
> ++++++++++++++++++++
> >> 2 files changed, 26 insertions(+), 1 deletion(-)
> >> ----------------------------------------------------------------------
> >>
> >>
> >>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33ee4bfd/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java
> >> ----------------------------------------------------------------------
> >> diff --git
> a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java
> b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java
> >> index c369a0b..c00645e 100644
> >> ---
> a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java
> >> +++
> b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java
> >> @@ -118,7 +118,7 @@ public class MapLookup implements StrLookup {
> >>
> >>    @Override
> >>    public String lookup(final LogEvent event, final String key) {
> >> -        final boolean isMapMessage = event.getMessage() instanceof
> MapMessage;
> >> +        final boolean isMapMessage = event != null &&
> event.getMessage() instanceof MapMessage;
> >>        if (map == null && !isMapMessage) {
> >>            return null;
> >>        }
> >>
> >>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33ee4bfd/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
> >> ----------------------------------------------------------------------
> >> diff --git
> a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
> b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
> >> index be550e3..5f26d15 100644
> >> ---
> a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
> >> +++
> b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
> >> @@ -20,6 +20,9 @@ import static org.junit.Assert.assertEquals;
> >>
> >> import java.util.HashMap;
> >>
> >> +import org.apache.logging.log4j.core.LogEvent;
> >> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
> >> +import org.apache.logging.log4j.message.MapMessage;
> >> import org.junit.Test;
> >>
> >> /**
> >> @@ -64,4 +67,26 @@ public class MapLookupTest {
> >>        assertEquals(null, lookup.lookup("foo.txt"));
> >>    }
> >>
> >> +    @Test
> >> +    public void testEventMapMessage() {
> >> +      final HashMap<String, String> map = new HashMap<>();
> >> +      map.put("A", "B");
> >> +      final HashMap<String, String> eventMap = new HashMap<>();
> >> +      eventMap.put("A1", "B1");
> >> +      final MapMessage message = new MapMessage(eventMap);
> >> +      final LogEvent event = Log4jLogEvent.newBuilder()
> >> +                .setMessage(message)
> >> +                .build();
> >> +      final MapLookup lookup = new MapLookup(map);
> >> +      assertEquals("B", lookup.lookup(event, "A"));
> >> +      assertEquals("B1", lookup.lookup(event, "A"));
> >> +    }
> >> +
> >> +    @Test
> >> +    public void testNullEvent() {
> >> +      final HashMap<String, String> map = new HashMap<>();
> >> +      map.put("A", "B");
> >> +      final MapLookup lookup = new MapLookup(map);
> >> +      assertEquals("B", lookup.lookup(null, "A"));
> >> +    }
> >> }
> >>
> >>
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-dev-help@logging.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>
>


-- 
Matt Sicker <bo...@gmail.com>

Re: [1/3] logging-log4j2 git commit: LOG4J2-1227 Test if the event is null before using it, to avoid NullPointerException. Add some unit tests. Submitted by: Olivier Lemasle

Posted by Ralph Goers <ra...@dslextreme.com>.
This test is still failing.

Ralph

> On Mar 2, 2016, at 10:34 PM, Ralph Goers <ra...@dslextreme.com> wrote:
> 
> It appears that the newly added testEventMapMessage is not working.
> 
> Ralph
> 
>> On Mar 2, 2016, at 8:08 PM, mattsicker@apache.org wrote:
>> 
>> Repository: logging-log4j2
>> Updated Branches:
>> refs/heads/master 60d1ccd93 -> a57fc35b9
>> 
>> 
>> LOG4J2-1227
>>   Test if the event is null before using it, to avoid NullPointerException.
>>   Add some unit tests.
>>   Submitted by: Olivier Lemasle <o....@gmail.com>
>> 
>> 
>> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/33ee4bfd
>> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/33ee4bfd
>> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/33ee4bfd
>> 
>> Branch: refs/heads/master
>> Commit: 33ee4bfd0aa1f58a705771222132a42d1dfb328c
>> Parents: 13b0dd8
>> Author: Olivier Lemasle <ol...@apalia.net>
>> Authored: Mon Dec 21 16:53:36 2015 +0100
>> Committer: Olivier Lemasle <ol...@apalia.net>
>> Committed: Mon Dec 21 16:53:36 2015 +0100
>> 
>> ----------------------------------------------------------------------
>> .../logging/log4j/core/lookup/MapLookup.java    |  2 +-
>> .../log4j/core/lookup/MapLookupTest.java        | 25 ++++++++++++++++++++
>> 2 files changed, 26 insertions(+), 1 deletion(-)
>> ----------------------------------------------------------------------
>> 
>> 
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33ee4bfd/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java
>> ----------------------------------------------------------------------
>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java
>> index c369a0b..c00645e 100644
>> --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java
>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java
>> @@ -118,7 +118,7 @@ public class MapLookup implements StrLookup {
>> 
>>    @Override
>>    public String lookup(final LogEvent event, final String key) {
>> -        final boolean isMapMessage = event.getMessage() instanceof MapMessage;
>> +        final boolean isMapMessage = event != null && event.getMessage() instanceof MapMessage;
>>        if (map == null && !isMapMessage) {
>>            return null;
>>        }
>> 
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33ee4bfd/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
>> ----------------------------------------------------------------------
>> diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
>> index be550e3..5f26d15 100644
>> --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
>> +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
>> @@ -20,6 +20,9 @@ import static org.junit.Assert.assertEquals;
>> 
>> import java.util.HashMap;
>> 
>> +import org.apache.logging.log4j.core.LogEvent;
>> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
>> +import org.apache.logging.log4j.message.MapMessage;
>> import org.junit.Test;
>> 
>> /**
>> @@ -64,4 +67,26 @@ public class MapLookupTest {
>>        assertEquals(null, lookup.lookup("foo.txt"));
>>    }
>> 
>> +    @Test
>> +    public void testEventMapMessage() {
>> +      final HashMap<String, String> map = new HashMap<>();
>> +      map.put("A", "B");
>> +      final HashMap<String, String> eventMap = new HashMap<>();
>> +      eventMap.put("A1", "B1");
>> +      final MapMessage message = new MapMessage(eventMap);
>> +      final LogEvent event = Log4jLogEvent.newBuilder()
>> +                .setMessage(message)
>> +                .build();
>> +      final MapLookup lookup = new MapLookup(map);
>> +      assertEquals("B", lookup.lookup(event, "A"));
>> +      assertEquals("B1", lookup.lookup(event, "A"));
>> +    }
>> +
>> +    @Test
>> +    public void testNullEvent() {
>> +      final HashMap<String, String> map = new HashMap<>();
>> +      map.put("A", "B");
>> +      final MapLookup lookup = new MapLookup(map);
>> +      assertEquals("B", lookup.lookup(null, "A"));
>> +    }
>> }
>> 
>> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Re: [1/3] logging-log4j2 git commit: LOG4J2-1227 Test if the event is null before using it, to avoid NullPointerException. Add some unit tests. Submitted by: Olivier Lemasle

Posted by Ralph Goers <ra...@dslextreme.com>.
It appears that the newly added testEventMapMessage is not working.

Ralph

> On Mar 2, 2016, at 8:08 PM, mattsicker@apache.org wrote:
> 
> Repository: logging-log4j2
> Updated Branches:
>  refs/heads/master 60d1ccd93 -> a57fc35b9
> 
> 
> LOG4J2-1227
>    Test if the event is null before using it, to avoid NullPointerException.
>    Add some unit tests.
>    Submitted by: Olivier Lemasle <o....@gmail.com>
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/33ee4bfd
> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/33ee4bfd
> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/33ee4bfd
> 
> Branch: refs/heads/master
> Commit: 33ee4bfd0aa1f58a705771222132a42d1dfb328c
> Parents: 13b0dd8
> Author: Olivier Lemasle <ol...@apalia.net>
> Authored: Mon Dec 21 16:53:36 2015 +0100
> Committer: Olivier Lemasle <ol...@apalia.net>
> Committed: Mon Dec 21 16:53:36 2015 +0100
> 
> ----------------------------------------------------------------------
> .../logging/log4j/core/lookup/MapLookup.java    |  2 +-
> .../log4j/core/lookup/MapLookupTest.java        | 25 ++++++++++++++++++++
> 2 files changed, 26 insertions(+), 1 deletion(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33ee4bfd/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java
> ----------------------------------------------------------------------
> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java
> index c369a0b..c00645e 100644
> --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java
> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java
> @@ -118,7 +118,7 @@ public class MapLookup implements StrLookup {
> 
>     @Override
>     public String lookup(final LogEvent event, final String key) {
> -        final boolean isMapMessage = event.getMessage() instanceof MapMessage;
> +        final boolean isMapMessage = event != null && event.getMessage() instanceof MapMessage;
>         if (map == null && !isMapMessage) {
>             return null;
>         }
> 
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33ee4bfd/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
> ----------------------------------------------------------------------
> diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
> index be550e3..5f26d15 100644
> --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
> +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java
> @@ -20,6 +20,9 @@ import static org.junit.Assert.assertEquals;
> 
> import java.util.HashMap;
> 
> +import org.apache.logging.log4j.core.LogEvent;
> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
> +import org.apache.logging.log4j.message.MapMessage;
> import org.junit.Test;
> 
> /**
> @@ -64,4 +67,26 @@ public class MapLookupTest {
>         assertEquals(null, lookup.lookup("foo.txt"));
>     }
> 
> +    @Test
> +    public void testEventMapMessage() {
> +      final HashMap<String, String> map = new HashMap<>();
> +      map.put("A", "B");
> +      final HashMap<String, String> eventMap = new HashMap<>();
> +      eventMap.put("A1", "B1");
> +      final MapMessage message = new MapMessage(eventMap);
> +      final LogEvent event = Log4jLogEvent.newBuilder()
> +                .setMessage(message)
> +                .build();
> +      final MapLookup lookup = new MapLookup(map);
> +      assertEquals("B", lookup.lookup(event, "A"));
> +      assertEquals("B1", lookup.lookup(event, "A"));
> +    }
> +
> +    @Test
> +    public void testNullEvent() {
> +      final HashMap<String, String> map = new HashMap<>();
> +      map.put("A", "B");
> +      final MapLookup lookup = new MapLookup(map);
> +      assertEquals("B", lookup.lookup(null, "A"));
> +    }
> }
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org