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

Scott Bartram commented on LOG4J2-2721:
---------------------------------------

Some observations on this bug (I think it is a bug):
 # The error message in MapMessage.put() says "No value provided for key " but 
the code is checking the value, not the key
 # The with(String, Object) method *does* accept null values so the behavior is 
inconsistent at best, broken at worst

See the implementations in JdkMapAdapterStringMap and SortedArrayStringMap

If this single line in MapMessage.put() was changed, I think it would fix it:

 
{code:java}
public void put(final String candidateKey, final String value) {

    if (value == null) {  // THIS SHOULD BE TESTING candidateKey NOT value
        throw new IllegalArgumentException("No value provided for key " + 
candidateKey);
    }
   final String key = toKey(candidateKey);
    validate(key, value);
    data.putValue(key, value);
}

{code}
 

> Thread crash when parameter is a null value for StringMapMessage
> ----------------------------------------------------------------
>
>                 Key: LOG4J2-2721
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2721
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: API
>    Affects Versions: 2.12.1
>            Reporter: Rémi C.
>            Priority: Major
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> {code:java}
> logger.info(myMarker, new StringMapMessage()
>  .with("message", "Test message")
>  .with("event.action", null)
>  .with("event.category", "General"));{code}
> This will crash. It is not supposed to happen, but sometimes a parameter can 
> be null unexpectedly.
>  
> MapMessage should be "null safe".
>  
> [https://github.com/apache/logging-log4j2/blob/master/log4j-api/src/main/java/org/apache/logging/log4j/message/MapMessage.java]
> line 732



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to