[ 
https://issues.apache.org/jira/browse/LOG4J2-2101?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16241239#comment-16241239
 ] 

ASF GitHub Bot commented on LOG4J2-2101:
----------------------------------------

Github user cakofony commented on a diff in the pull request:

    https://github.com/apache/logging-log4j2/pull/124#discussion_r149243922
  
    --- Diff: 
log4j-api/src/test/java/org/apache/logging/log4j/message/MapMessageTest.java ---
    @@ -99,4 +102,29 @@ public void testMutableByDesign() { // LOG4J2-763
             final String expected2 = "{key1=\"value1\", key2=\"value2\", 
key3=\"value3\"}";
             assertEquals(expected2, result2);
         }
    +
    +    @Test
    +    public void testGetNonStringValue() {
    +        final String key = "Key";
    +        final MapMessage<?, Object> msg = new MapMessage<>()
    +                .with(key, 1L);
    +        assertEquals("1", msg.get(key));
    +    }
    +
    +    @Test
    +    public void testRemoveNonStringValue() {
    +        final String key = "Key";
    +        final MapMessage<?, Object> msg = new MapMessage<>()
    +                .with(key, 1L);
    +        assertEquals("1", msg.remove(key));
    +    }
    +
    +    @Test
    +    public void testJSONFormatNonStringValue() {
    --- End diff --
    
    Updated. Good call, turns out it was broken!


> non-string value MapMessage ClassCastException
> ----------------------------------------------
>
>                 Key: LOG4J2-2101
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2101
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Filters
>    Affects Versions: 2.9.1
>            Reporter: Carter Douglas Kozak
>
> Using a MapFilter with a MapMessage containing non-string values results in a 
> ClassCastException attempting to cast values to strings.
> {noformat}
> ClassCastException: java.lang.Long cannot be cast to java.lang.String
>     at org.apache.logging.log4j.message.MapMessage.get(MapMessage.java:214)
>     at 
> org.apache.logging.log4j.core.filter.MapFilter.filter(MapFilter.java:87)
>     at 
> org.apache.logging.log4j.core.filter.MapFilter.filter(MapFilter.java:79)
>     at 
> org.apache.logging.log4j.core.filter.AbstractFilterable.isFiltered(AbstractFilterable.java:182)
>     at 
> org.apache.logging.log4j.core.config.AppenderControl.isFilteredByAppender(AppenderControl.java:151)
>     at 
> org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:128)
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to