Skip to content

Commit

Permalink
add null checks before accessing jsonParserConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
Simulant87 committed Jan 8, 2025
1 parent dc10ec9 commit 0631db1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/json/JSONArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ public JSONArray(JSONTokener x, JSONParserConfiguration jsonParserConfiguration)
}
if (nextChar == ']') {
// trailing commas are not allowed in strict mode
if (jsonParserConfiguration.isStrictMode()) {
if (jsonParserConfiguration != null && jsonParserConfiguration.isStrictMode()) {
throw x.syntaxError("Strict mode error: Expected another array element");
}
return;
}
if (nextChar == ',') {
// consecutive commas are not allowed in strict mode
if (jsonParserConfiguration.isStrictMode()) {
if (jsonParserConfiguration != null && jsonParserConfiguration.isStrictMode()) {
throw x.syntaxError("Strict mode error: Expected a valid array element");
}
return;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/json/JSONObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public JSONObject(JSONTokener x, JSONParserConfiguration jsonParserConfiguration
if (key != null) {
// Check if key exists
boolean keyExists = this.opt(key) != null;
if (keyExists && !jsonParserConfiguration.isOverwriteDuplicateKey()) {
if (keyExists && jsonParserConfiguration != null && !jsonParserConfiguration.isOverwriteDuplicateKey()) {
throw x.syntaxError("Duplicate key \"" + key + "\"");
}

Expand All @@ -271,13 +271,13 @@ public JSONObject(JSONTokener x, JSONParserConfiguration jsonParserConfiguration
switch (x.nextClean()) {
case ';':
// In strict mode semicolon is not a valid separator
if (jsonParserConfiguration.isStrictMode()) {
if (jsonParserConfiguration != null && jsonParserConfiguration.isStrictMode()) {
throw x.syntaxError("Strict mode error: Invalid character ';' found");
}
case ',':
if (x.nextClean() == '}') {
// trailing commas are not allowed in strict mode
if (jsonParserConfiguration.isStrictMode()) {
if (jsonParserConfiguration != null && jsonParserConfiguration.isStrictMode()) {
throw x.syntaxError("Strict mode error: Expected another object element");
}
return;
Expand Down

0 comments on commit 0631db1

Please sign in to comment.