skyscreamer / JSONassert

Write JSON unit tests in less code. Great for testing REST interfaces.
http://jsonassert.skyscreamer.org
Apache License 2.0
1k stars 197 forks source link

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

Open hezonghan opened 3 years ago

hezonghan commented 3 years ago

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 commented 2 years ago

I will take this.