Skip to content

Commit ffd48af

Browse files
committed
Review comments
1 parent abea194 commit ffd48af

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

src/main/java/org/json/JSONParserConfiguration.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,21 @@
55
*/
66
public class JSONParserConfiguration extends ParserConfiguration {
77

8-
/**
9-
* We can override the default maximum nesting depth if needed.
10-
*/
11-
public static final int DEFAULT_MAXIMUM_NESTING_DEPTH = ParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH;
12-
138
/**
149
* Configuration with the default values.
1510
*/
1611
public JSONParserConfiguration() {
17-
this.maxNestingDepth = DEFAULT_MAXIMUM_NESTING_DEPTH;
12+
super();
1813
}
1914

20-
public JSONParserConfiguration(int maxNestingDepth) {
21-
this.maxNestingDepth = maxNestingDepth;
15+
@Override
16+
protected JSONParserConfiguration clone() {
17+
return new JSONParserConfiguration();
2218
}
2319

2420
@Override
25-
protected JSONParserConfiguration clone() {
26-
return new JSONParserConfiguration(DEFAULT_MAXIMUM_NESTING_DEPTH);
21+
public JSONParserConfiguration withMaxNestingDepth(final int maxNestingDepth) {
22+
return super.withMaxNestingDepth(maxNestingDepth);
2723
}
2824

2925
}

src/test/java/org/json/junit/JSONArrayTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.json.JSONPointerException;
3333
import org.json.JSONString;
3434
import org.json.JSONTokener;
35+
import org.json.ParserConfiguration;
3536
import org.json.junit.data.MyJsonString;
3637
import org.junit.Ignore;
3738
import org.junit.Test;
@@ -1442,14 +1443,14 @@ public void testRecursiveDepthArray() {
14421443

14431444
@Test
14441445
public void testRecursiveDepthAtPositionDefaultObject() {
1445-
HashMap<String, Object> map = JSONObjectTest.buildNestedMap(JSONParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH);
1446+
HashMap<String, Object> map = JSONObjectTest.buildNestedMap(ParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH);
14461447
new JSONArray().put(0, map);
14471448
}
14481449

14491450
@Test
14501451
public void testRecursiveDepthAtPosition1000Object() {
14511452
HashMap<String, Object> map = JSONObjectTest.buildNestedMap(1000);
1452-
new JSONArray().put(0, map, new JSONParserConfiguration(1000));
1453+
new JSONArray().put(0, map, new JSONParserConfiguration().withMaxNestingDepth(1000));
14531454
}
14541455

14551456
@Test(expected = JSONException.class)
@@ -1467,14 +1468,14 @@ public void testRecursiveDepthArrayLimitedMaps() {
14671468

14681469
@Test
14691470
public void testRecursiveDepthArrayForDefaultLevels() {
1470-
ArrayList<Object> array = buildNestedArray(JSONParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH);
1471+
ArrayList<Object> array = buildNestedArray(ParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH);
14711472
new JSONArray(array, new JSONParserConfiguration());
14721473
}
14731474

14741475
@Test
14751476
public void testRecursiveDepthArrayFor1000Levels() {
14761477
ArrayList<Object> array = buildNestedArray(1000);
1477-
JSONParserConfiguration parserConfiguration = new JSONParserConfiguration(1000);
1478+
JSONParserConfiguration parserConfiguration = new JSONParserConfiguration().withMaxNestingDepth(1000);
14781479
new JSONArray(array, parserConfiguration);
14791480
}
14801481

src/test/java/org/json/junit/JSONObjectTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.json.JSONParserConfiguration;
3636
import org.json.JSONString;
3737
import org.json.JSONTokener;
38+
import org.json.ParserConfiguration;
3839
import org.json.XML;
3940
import org.json.junit.data.BrokenToString;
4041
import org.json.junit.data.ExceptionalBean;
@@ -3739,15 +3740,15 @@ public void testCircularReferenceMultipleLevel() {
37393740

37403741
@Test
37413742
public void issue743SerializationMapWith512Objects() {
3742-
HashMap<String, Object> map = buildNestedMap(JSONParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH);
3743+
HashMap<String, Object> map = buildNestedMap(ParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH);
37433744
JSONObject object = new JSONObject(map);
37443745
String jsonString = object.toString();
37453746
}
37463747

37473748
@Test
37483749
public void issue743SerializationMapWith1000Objects() {
37493750
HashMap<String, Object> map = buildNestedMap(1000);
3750-
JSONParserConfiguration parserConfiguration = new JSONParserConfiguration(1000);
3751+
JSONParserConfiguration parserConfiguration = new JSONParserConfiguration().withMaxNestingDepth(1000);
37513752
JSONObject object = new JSONObject(map, parserConfiguration);
37523753
String jsonString = object.toString();
37533754
}

0 commit comments

Comments
 (0)