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

NullPointerException at JSONCompareResult.describe #171

Open
leonidng opened this issue Feb 23, 2023 · 0 comments · May be fixed by #172
Open

NullPointerException at JSONCompareResult.describe #171

leonidng opened this issue Feb 23, 2023 · 0 comments · May be fixed by #172

Comments

@leonidng
Copy link

If expected or actual value in DefaultComparator.compareValues(...) is null then a NullPointerException will be thrown by formatting of message.

org.skyscreamer:jsonassert:1.5.1

java.lang.NullPointerException: Cannot invoke "Object.toString()" because "value" is null

at org.skyscreamer.jsonassert.JSONCompareResult.describe(JSONCompareResult.java:248)
at org.skyscreamer.jsonassert.JSONCompareResult.formatFailureMessage(JSONCompareResult.java:200)
at org.skyscreamer.jsonassert.JSONCompareResult.fail(JSONCompareResult.java:180)
at org.skyscreamer.jsonassert.comparator.DefaultComparator.compareValues(DefaultComparator.java:57)
at org.skyscreamer.jsonassert.comparator.CustomComparator.compareValues(CustomComparator.java:48)

Proposal: Replace lines (in DefaultComparator.compareValues(...))

        if ((expectedValue == null && actualValue != null) || (expectedValue != null && actualValue == null)) {
            result.fail(prefix, expectedValue, actualValue);
        }

to

        if (expectedValue == null && actualValue != null) {
            result.unexpected(prefix, actualValue);
        }
        if (expectedValue != null && actualValue == null) {
            result.missing(prefix, expectedValue);
        }
@MikeEdgar MikeEdgar linked a pull request Apr 2, 2023 that will close this issue
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.

1 participant