Visitar URL original
NPE with custom `RecursiveComparisonConfiguration` on `usingRecursiveFieldByFieldElementComparator` · Issue #3719 · assertj/assertj · GitHub
Skip to content

NPE with custom RecursiveComparisonConfiguration on usingRecursiveFieldByFieldElementComparator #3719

Closed

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

Activity

  1. scordio commented on Dec 30, 2024

    @scordio
    Member

    Thanks for the reproducer, @mofleury! We'll check if we can manage to squeeze this in 3.27.1.

  2. changed the title [-]NullPointerException with custom RecursiveComparisonConfiguration on usingRecursiveFieldByFieldElementComparator[/-] [+]NullPointerException with custom `RecursiveComparisonConfiguration` on `usingRecursiveFieldByFieldElementComparator`[/+] on Dec 30, 2024
  3. changed the title [-]NullPointerException with custom `RecursiveComparisonConfiguration` on `usingRecursiveFieldByFieldElementComparator`[/-] [+]NPE with custom `RecursiveComparisonConfiguration` on `usingRecursiveFieldByFieldElementComparator`[/+] on Dec 30, 2024
  4. added this to the 3.27.1 milestone on Dec 30, 2024
  5. added a commit that references this issue on Jan 3, 2025
    8030727
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions