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

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

Open
hezonghan opened this issue Mar 12, 2021 · 1 comment · May be fixed by #153
Open

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

hezonghan opened this issue Mar 12, 2021 · 1 comment · May be fixed by #153

Comments

@hezonghan
Copy link

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.

@zihanxu3
Copy link

zihanxu3 commented Dec 8, 2021

I will take this.

zihanxu3 added a commit to zihanxu3/JSONassert that referenced this issue Dec 8, 2021
zihanxu3 added a commit to zihanxu3/JSONassert that referenced this issue Dec 8, 2021
zihanxu3 added a commit to zihanxu3/JSONassert that referenced this issue Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants