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

Regression in AbstractMapAssert.containsExactly causes NullPointerException #3317

Closed
sbrannen opened this issue Jan 2, 2024 · 4 comments · Fixed by #3321
Closed

Regression in AbstractMapAssert.containsExactly causes NullPointerException #3317

sbrannen opened this issue Jan 2, 2024 · 4 comments · Fixed by #3321
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@sbrannen
Copy link
Contributor

sbrannen commented Jan 2, 2024

Describe the bug

  • assertj core version: 3.25.0

Commit 498ee5b introduced a regression in AbstractMapAssert.containsExactly.

Specifically, it is not always safe to put null into a Map.

Test case reproducing the bug

The following now fails with a NullPointerException.

@Test
void assertJBug() {
	Properties properties = new Properties();
	properties.setProperty("k1", "v1");
	properties.setProperty("k2", "v2");
	assertThat(properties).containsExactly(entry("k1", "v1"), entry("k2", "v2"));
}
@scordio scordio added this to the 3.25.1 milestone Jan 2, 2024
@scordio scordio added the type: regression A regression from a previous release label Jan 2, 2024
@scordio
Copy link
Member

scordio commented Jan 2, 2024

Thanks for reporting it and the analysis, @sbrannen!

@sbrannen
Copy link
Contributor Author

sbrannen commented Jan 2, 2024

In case anyone else runs into this, you may find the workaround I came up with suitable for your use case as well.

spring-projects/spring-framework@ffddbb5#diff-6f347f5b75cdbb58d65e5ec32c8e3ffe9abf719f50f3bc819ec257296d466aee

Basically, I created a new map (LinkedHashMap in this case) based on the original map (Properties in this case), and the NullPointerException is avoided since LinkedHashMap supports null values.

@scordio scordio self-assigned this Jan 2, 2024
@scordio
Copy link
Member

scordio commented Jan 2, 2024

Team decision: 498ee5b should be reverted and #2165 should be addressed again with the knowledge gathered from this issue.

@sbrannen
Copy link
Contributor Author

sbrannen commented Jan 3, 2024

Thanks for the quick turnaround! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
2 participants