Skip to content

NoSuchElementException from CompareMatcher#describeTo(Description) #107

@chludwig-haufe

Description

@chludwig-haufe

One of our integration tests fails with a NoSuchElementException escaping from CompareMatcher#describeTo(Description). We use org.xmlunit:xmlunit-matchers:2.5.0.

In the debugger, I can see that the matcher's diffResult is != null, but diffResult.hasDifferences() == false. Since describeTo(Description) only checks for diffResult == null, the code flow enters ComparisonMatcher#firstComparison() where the subexpression diffResult.getDifferences().iterator().next() throws the NoSuchElementException.

The fix seems easy: Simply test for diffResult == null || !diffResult.hasDifferences() at the beginning of CompareMatcher#describeTo(Description).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions