Skip to content

Commit 0631db1

Browse files
committed
add null checks before accessing jsonParserConfiguration
1 parent dc10ec9 commit 0631db1

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/main/java/org/json/JSONArray.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ public JSONArray(JSONTokener x, JSONParserConfiguration jsonParserConfiguration)
141141
}
142142
if (nextChar == ']') {
143143
// trailing commas are not allowed in strict mode
144-
if (jsonParserConfiguration.isStrictMode()) {
144+
if (jsonParserConfiguration != null && jsonParserConfiguration.isStrictMode()) {
145145
throw x.syntaxError("Strict mode error: Expected another array element");
146146
}
147147
return;
148148
}
149149
if (nextChar == ',') {
150150
// consecutive commas are not allowed in strict mode
151-
if (jsonParserConfiguration.isStrictMode()) {
151+
if (jsonParserConfiguration != null && jsonParserConfiguration.isStrictMode()) {
152152
throw x.syntaxError("Strict mode error: Expected a valid array element");
153153
}
154154
return;

src/main/java/org/json/JSONObject.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public JSONObject(JSONTokener x, JSONParserConfiguration jsonParserConfiguration
255255
if (key != null) {
256256
// Check if key exists
257257
boolean keyExists = this.opt(key) != null;
258-
if (keyExists && !jsonParserConfiguration.isOverwriteDuplicateKey()) {
258+
if (keyExists && jsonParserConfiguration != null && !jsonParserConfiguration.isOverwriteDuplicateKey()) {
259259
throw x.syntaxError("Duplicate key \"" + key + "\"");
260260
}
261261

@@ -271,13 +271,13 @@ public JSONObject(JSONTokener x, JSONParserConfiguration jsonParserConfiguration
271271
switch (x.nextClean()) {
272272
case ';':
273273
// In strict mode semicolon is not a valid separator
274-
if (jsonParserConfiguration.isStrictMode()) {
274+
if (jsonParserConfiguration != null && jsonParserConfiguration.isStrictMode()) {
275275
throw x.syntaxError("Strict mode error: Invalid character ';' found");
276276
}
277277
case ',':
278278
if (x.nextClean() == '}') {
279279
// trailing commas are not allowed in strict mode
280-
if (jsonParserConfiguration.isStrictMode()) {
280+
if (jsonParserConfiguration != null && jsonParserConfiguration.isStrictMode()) {
281281
throw x.syntaxError("Strict mode error: Expected another object element");
282282
}
283283
return;

0 commit comments

Comments
 (0)