Skip to content

MDCContextMap::getCopy can return null causing an NPE in CloseableThreadContext #1426

Closed
@jvz

Description

@jvz

Description

MDCContextMap::getCopy delegates to MDC::getCopyOfContextMap which is documented as potentially returning null. This fact is respected within MDCContextMap, but ThreadContextMap::getCopy is documented as returning a non-null value. In CloseableThreadContext.Instance, this causes NullPointerExceptions in the putAll method when ThreadContext::getContext is invoked and later used.

Configuration

Version: 2.20.0

Operating system: [OS and version]

JDK: [JDK distribution and version]

Logs

java.lang.NullPointerException: null
        at org.apache.logging.log4j.CloseableThreadContext$Instance.putAll(CloseableThreadContext.java:170)
        at org.apache.logging.log4j.CloseableThreadContext.putAll(CloseableThreadContext.java:100)

Reproduction

[An isolated test reproducing the test.
JUnit tests similar to the ones in the code base are extremely appreciated.]

Metadata

Metadata

Assignees

Labels

apiAffects the public APIbugIncorrect, unexpected, or unintended behavior of existing codegood first issueIssues that are good for contributors looking to get startedslf4jAffects SLF4J integration

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions