diff --git a/subprojects/json-lib-core/src/main/java/org/kordamp/json/util/JSONTokener.java b/subprojects/json-lib-core/src/main/java/org/kordamp/json/util/JSONTokener.java index 17a5af5..f746931 100644 --- a/subprojects/json-lib-core/src/main/java/org/kordamp/json/util/JSONTokener.java +++ b/subprojects/json-lib-core/src/main/java/org/kordamp/json/util/JSONTokener.java @@ -203,6 +203,8 @@ public char nextClean() { if (c == '*') { if (next() == '/') { break; + } else if (!more()) { + return 0; } back(); } diff --git a/subprojects/json-lib-core/src/test/java/org/kordamp/json/TestJSONSerializer.java b/subprojects/json-lib-core/src/test/java/org/kordamp/json/TestJSONSerializer.java index 4298492..ff6d311 100644 --- a/subprojects/json-lib-core/src/test/java/org/kordamp/json/TestJSONSerializer.java +++ b/subprojects/json-lib-core/src/test/java/org/kordamp/json/TestJSONSerializer.java @@ -144,6 +144,15 @@ public void testToJava_JSONObject_4() { assertEquals(beanB.getValue(), ((ValueBean) bb).getValue()); } + public void testToJava_JSONObject_5() throws Exception { + try { + JSONObject.fromObject("/**"); + fail("Should have thrown a JSONException"); + } catch (JSONException expected) { + // ok + } + } + public void testToJava_JSONObject_and_reset() throws Exception { String json = "{bool:true,integer:1,string:\"json\"}"; JSONObject jsonObject = JSONObject.fromObject(json);