[slf4j-dev] Stack-valued MDC in SLF4J 2.0
Piotr P. Karwasz
piotr.karwasz at gmail.com
Sun Aug 28 22:55:42 CEST 2022
Hi all,
I am implementing the new MDC methods in the Log4j2 bridge and I have
some questions on the behavior of the `popByKey/pushByKey`, that I
couldn't resolve reading the Javadoc[1].
Regarding 'pushByKey(key, value)':
* can the key be null? The `BasicMDCAdapter` implementation does not
allow it/ignores it, but this could be a good way to reference
Reload4j/Log4j's NDC,
* can the value be null? The current implementation does not allow
them and the Deque Javadoc discourages adding null to a deque, but
SLF4J Javadoc is not precise in this matter (e.g. it does not contain
'@throws NullPointerException if the value is null'),
* is the Deque limited in size?
Regarding `popByKey(key, value)':
* the Javadoc suggests that popping an empty stack returns null, while
the `BasicMDCAdapter` implementation delegates to `Deque#pop()` which
throws a `NoSuchElementException`. Is it a bug or an undocumented
feature? By comparison popping the NDC in Log4j/Reload4j returns null
if the stack is empty, while Log4j2 throws an exception.
Piotr
[1] https://www.slf4j.org/api/org/slf4j/MDC.html
More information about the slf4j-dev
mailing list