Skip to content

NPE with custom RecursiveComparisonConfiguration on usingRecursiveFieldByFieldElementComparator #3719

@mofleury

Description

@mofleury

Describe the bug
When using usingRecursiveFieldByFieldElementComparator with a custom RecursiveComparisonConfiguration, it is possible that the Representation is null, which leads to a NullPointerException instead of a failed assertion.

  • assertj core version: 3.27.0
  • java version: 17
  • test framework version: junit-jupiter 5.11.4

Note that it is possible to work around the NPE by setting the default representation, using recursiveComparisonConfiguration.withRepresentation(CONFIGURATION_PROVIDER.representation())

Test case reproducing the bug

	@Test
	void usingRecursiveFieldByFieldElementComparatorNPE() {
		List<List<String>> input = List.of(List.of("list", "one"));
		assertThat(input)
				.usingRecursiveFieldByFieldElementComparator(RecursiveComparisonConfiguration.builder()
						.withIgnoreCollectionOrder(true)
						.build())
				.containsExactlyInAnyOrder(List.of("another", "list"));
	}

this results in a NullPointerException with this message:

java.lang.NullPointerException: Cannot invoke "org.assertj.core.presentation.Representation.toStringOf(Object)" because the return value of "org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration.getRepresentation()" is null

Metadata

Metadata

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions