Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jvz opened this issue Apr 13, 2023 · 2 comments · Fixed by #2115
Closed

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

jvz opened this issue Apr 13, 2023 · 2 comments · Fixed by #2115
Assignees
Labels
api Affects the public API bug Incorrect, unexpected, or unintended behavior of existing code good first issue Issues that are good for contributors looking to get started slf4j Affects SLF4J integration
Milestone

Comments

@jvz
Copy link
Member

jvz commented Apr 13, 2023

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.]

@jvz jvz added bug Incorrect, unexpected, or unintended behavior of existing code api Affects the public API labels Apr 13, 2023
@jvz jvz added good first issue Issues that are good for contributors looking to get started slf4j Affects SLF4J integration labels Oct 27, 2023
jvz added a commit to jvz/logging-log4j2 that referenced this issue Nov 21, 2023
Also fixes apache#1426 while we're here.

Signed-off-by: Matt Sicker <[email protected]>
@benkeil
Copy link

benkeil commented Dec 19, 2023

any news on this?

@ppkarwasz ppkarwasz added this to the 2.22.1 milestone Dec 19, 2023
@ppkarwasz ppkarwasz self-assigned this Dec 19, 2023
@ppkarwasz
Copy link
Contributor

@benkeil,

Can you provide a PR?

dongjoon-hyun pushed a commit to apache/spark that referenced this issue Jan 11, 2024
### What changes were proposed in this pull request?
This pr aims to upgrade log4j2 from 2.22.0 to 2.22.1.

### Why are the changes needed?
The new version contains some bug fixes:
- [Fix NPE in CloseableThreadContext](apache/logging-log4j2#1426)
- [Fix NPE in RollingFileManager](apache/logging-log4j2#1645)

And 2.22.1 is generated using JDK 17, the full release note as follows:
- https://github.com/apache/logging-log4j2/releases/tag/rel%2F2.22.1

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Pass GitHub Actions

### Was this patch authored or co-authored using generative AI tooling?
No

Closes #44682 from LuciferYang/SPARK-46672.

Authored-by: yangjie01 <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Affects the public API bug Incorrect, unexpected, or unintended behavior of existing code good first issue Issues that are good for contributors looking to get started slf4j Affects SLF4J integration
Projects
None yet
3 participants