When using the SLF4J adapter and you call ThreadContext.containsKey() before putting anything into the ThreadContext, a NullPointerException is thrown:
This is not surprising, as the implementation looks like this
And the Javadoc for getCopyOfContextMap explicitly states “May be null.”
This bug is also present in the isEmpty method of the same class.
Workaround: Before any tests are made, e.g. top of main, execute the following
I will create a pull request shortly.
UPDATE: Here is the pull request: https://github.com/apache/logging-log4j2/pull/430