From a25f83a0e4301d1ab146ab69b57b1521d32ca6bd Mon Sep 17 00:00:00 2001 From: XIAYM-gh Date: Thu, 10 Sep 2026 17:47:29 +0800 Subject: [PATCH] Strip JSONTokener#isAtStart() --- src/main/java/org/json/JSONArray.java | 2 +- src/main/java/org/json/JSONObject.java | 2 +- src/main/java/org/json/JSONTokener.java | 22 ---------------------- 3 files changed, 2 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/json/JSONArray.java b/src/main/java/org/json/JSONArray.java index d5fb170..2bd80c1 100644 --- a/src/main/java/org/json/JSONArray.java +++ b/src/main/java/org/json/JSONArray.java @@ -94,7 +94,7 @@ public class JSONArray implements Iterable { * @throws JSONException If a syntax error occurs during the construction of the JSONArray. */ public JSONArray(JSONTokener x, JSONParserConfiguration jsonParserConfiguration) throws JSONException { - this(x, jsonParserConfiguration, x.isAtStart()); + this(x, jsonParserConfiguration, true); } /** diff --git a/src/main/java/org/json/JSONObject.java b/src/main/java/org/json/JSONObject.java index 295dea4..0b2268c 100644 --- a/src/main/java/org/json/JSONObject.java +++ b/src/main/java/org/json/JSONObject.java @@ -214,7 +214,7 @@ public class JSONObject { * duplicated key. */ public JSONObject(JSONTokener x, JSONParserConfiguration jsonParserConfiguration) throws JSONException { - this(x, jsonParserConfiguration, x.isAtStart()); + this(x, jsonParserConfiguration, true); } /** diff --git a/src/main/java/org/json/JSONTokener.java b/src/main/java/org/json/JSONTokener.java index 2eaeede..60660b0 100644 --- a/src/main/java/org/json/JSONTokener.java +++ b/src/main/java/org/json/JSONTokener.java @@ -31,8 +31,6 @@ public class JSONTokener { private boolean usePrevious; /** the number of characters read in the previous line. */ private long characterPreviousLine; - /** number of non-whitespace characters read from the source. */ - private long contentCharCount; // access to this object is required for strict mode checking private JSONParserConfiguration jsonParserConfiguration; @@ -62,7 +60,6 @@ public class JSONTokener { this.usePrevious = false; this.previous = 0; this.index = 0; - this.contentCharCount = 0; this.character = 1; this.characterPreviousLine = 0; this.line = 1; @@ -123,17 +120,6 @@ public class JSONTokener { this.jsonParserConfiguration = jsonParserConfiguration; } - /** - * Returns whether the tokener is positioned at the beginning, - * i.e. only whitespace characters (or no characters at all) have been read so far. - * Consuming and backing up over the first characters does not change the result. - * - * @return true if no non-whitespace character has been read - */ - protected boolean isAtStart() { - return this.contentCharCount == 0; - } - /** * Back up one character. This provides a sort of lookahead capability, * so that you can test for a digit or letter before attempting to parse @@ -145,9 +131,6 @@ public class JSONTokener { if (this.usePrevious || this.index <= 0) { throw new JSONException("Stepping back two steps is not supported"); } - if (this.previous > ' ') { - this.contentCharCount--; - } this.decrementIndexes(); this.usePrevious = true; this.eof = false; @@ -248,9 +231,6 @@ public class JSONTokener { return 0; } this.incrementIndexes(c); - if (c > ' ') { - this.contentCharCount++; - } this.previous = (char) c; return this.previous; } @@ -569,7 +549,6 @@ public class JSONTokener { long startIndex = this.index; long startCharacter = this.character; long startLine = this.line; - long startContentCharCount = this.contentCharCount; this.reader.mark(1000000); do { c = this.next(); @@ -581,7 +560,6 @@ public class JSONTokener { this.index = startIndex; this.character = startCharacter; this.line = startLine; - this.contentCharCount = startContentCharCount; return 0; } } while (c != to);