Skip to content

Commit ccc44f4

Browse files
committed
Checking for null JSON strings prior to the JSONCompare so that it doesn't throw a NullPointerException.
1 parent 8c9cf78 commit ccc44f4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/main/java/org/skyscreamer/jsonassert/JSONAssert.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ public static void assertNotEquals(String expectedStr, String actualStr, boolean
217217
*/
218218
public static void assertEquals(String expectedStr, String actualStr, JSONCompareMode compareMode)
219219
throws JSONException {
220+
if (expectedStr==actualStr) return;
221+
if (expectedStr==null){
222+
throw new AssertionError("Expected string is null.");
223+
}else if (actualStr==null){
224+
throw new AssertionError("Actual string is null.");
225+
}
220226
JSONCompareResult result = JSONCompare.compareJSON(expectedStr, actualStr, compareMode);
221227
if (result.failed()) {
222228
throw new AssertionError(result.getMessage());

0 commit comments

Comments
 (0)