Skip to content

assertEquals(...) may throw NullPointerException when given invalid JSON string  #130

Open
@hezonghan

Description

@hezonghan

The following line,
JSONAssert.assertEquals("[{id:1},]" , "[{id:1},{}]" , true);,
which inputs an invalid JSON string "[{id:1},]" to assertEquals,
will throw java.lang.NullPointerException.
(I think the string is invalid because the JsonArray contains no more element after a comma.)

By the way, the following line,
JSONAssert.assertEquals("[{id:1},]" , "[{id:1},{}]" , false);,
throws org.json.JSONException: Value at 1 is null. Maybe this exception is expected rather than NullPointerException?

The following lines does not throw anything:
JSONAssert.assertNotEquals("[{id:1},]" , "[{id:2},]" , true); // pass
JSONAssert.assertEquals("[{id:1},]" , "[{id:1},]" , true); // pass

These examples are related to invalid JSON strings, which are inspired by example from another issue #127 talking about the length of invalid JsonArray.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions