Skip to content

Commit 7d83534

Browse files
committed
Adding JSONTokener.back() just before throwing JSONException
This forces JSONTokener.syntaxError(..) to point to the last character of the duplicate key.
1 parent 7fed023 commit 7d83534

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

JSONObject.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,13 @@ public JSONObject(JSONTokener x) throws JSONException {
232232
throw x.syntaxError("Expected a ':' after a key");
233233
}
234234

235-
// Replace: this.putOnce(key, x.nextValue());
236235
// Use syntaxError(..) to include error location
237236

238237
if (key != null) {
239238
// Check if key exists
240239
if (this.opt(key) != null) {
240+
// back one token to point to the last key character
241+
x.back();
241242
throw x.syntaxError("Duplicate key \"" + key + "\"");
242243
}
243244
// Only add value if non-null

0 commit comments

Comments
 (0)