From 20a6340326a6f2e1ef66aeeea5d2a0a4d0f7c09d Mon Sep 17 00:00:00 2001 From: Simulant Date: Wed, 8 Jan 2025 22:46:34 +0100 Subject: [PATCH] add test for invalid input on JSONTokener expect JSONException but got NullPointerException --- src/test/java/org/json/junit/JSONTokenerTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/org/json/junit/JSONTokenerTest.java b/src/test/java/org/json/junit/JSONTokenerTest.java index 59ca6d8f6..1cb198dc6 100644 --- a/src/test/java/org/json/junit/JSONTokenerTest.java +++ b/src/test/java/org/json/junit/JSONTokenerTest.java @@ -325,4 +325,11 @@ public void testAutoClose(){ assertEquals("Stream closed", exception.getMessage()); } } + + @Test + public void testInvalidInput_shouldThrowJSONException() { + String input = "{\"invalidInput\": [],}"; + JSONTokener tokener = new JSONTokener(input); + assertThrows(JSONException.class, () -> tokener.nextValue()); + } }