[
https://issues.apache.org/jira/browse/LOG4J2-2721?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16976887#comment-16976887
]
Remko Popma commented on LOG4J2-2721:
-------------------------------------
If you look at the javadoc for
[MapMessage.get|https://logging.apache.org/log4j/2.x/log4j-api/apidocs/org/apache/logging/log4j/message/MapMessage.html#get-java.lang.String-],
you will see that it returns {{null}} if the specified key does not exist in
the map.
At the moment the contract is that MapMessage cannot have null values. It is
true that this is not documented in the javadoc for the put method, and we
should document that.
What you are suggesting is that {{MapMessage.put(key, null)}} should internally
be implemented as {{put(key, "null")}}, silently replacing the value that the
application specified with another value. I am not in favor of doing that now,
that may be surprising for other users.
My position is that applications that want to put a {{null}} value for any
reason, should do so explicitly, and should choose their own sentinel value to
represent {{null}}.
> 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)