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

TestMDCAdapter::setContextMap‎ causes NullpointerException with TreeMap #413

Closed
hoefi opened this issue Jul 12, 2023 · 1 comment · Fixed by #414
Closed

TestMDCAdapter::setContextMap‎ causes NullpointerException with TreeMap #413

hoefi opened this issue Jul 12, 2023 · 1 comment · Fixed by #414
Milestone

Comments

@hoefi
Copy link

hoefi commented Jul 12, 2023

TestMDCAdapter::setContextMap‎ throws a NullpointerException when a TreeMap is used as a parameter.

I think it is caused by this line:
https://github.com/valfirst/slf4j-test/blob/139d72855228aabfe1d64f52ee42e0ddd061757b/src/main/java/com/github/valfirst/slf4jtest/TestMDCAdapter.java#L132C16-L132C16

containsKey with a null parameter is quite likely to cause an NullpointerException on a TreeMap (e.g. no specific comperator supporting null keys is set. See TreeMap::containsKey)

Source of that TreeMap could be TestMDCAdapter::getCopyOfContextMap.

UnitTest to validate:

@Test
    void setContextMapSetsCopy() {
        Map<String, String> newValues = new TreeMap<>();
        newValues.put(key, value);
        testMDCAdapter.setContextMap(newValues);
        Map<String, String> expected = new HashMap<>(newValues);
        newValues.clear();
        assertEquals(expected, testMDCAdapter.getCopyOfContextMap());
    }
@hoefi
Copy link
Author

hoefi commented Jul 13, 2023

thank you for the quick response. 3.0.1 runs smoothly in our tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants