Skip to content

Commit d9da808

Browse files
committed
Introducing new static methods to set the recursion depth limit
1 parent 888eec8 commit d9da808

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

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

+20
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,16 @@ static String valueToString(Object value, int indentFactor, int indent, boolean
13461346
* value is 500
13471347
* @param newRecursionDepthLimit the new recursion depth limit to set
13481348
*/
1349+
public static void setGlobalRecursionDepthLimit(int newRecursionDepthLimit) {
1350+
RECURSION_DEPTH_LIMIT = newRecursionDepthLimit;
1351+
}
1352+
1353+
/**
1354+
* Set the new recursion depth limit to prevent stack overflow issues on deeply nested structures. The default
1355+
* value is 500
1356+
* @param newRecursionDepthLimit the new recursion depth limit to set
1357+
*/
1358+
@Deprecated
13491359
public void setRecursionDepthLimit(int newRecursionDepthLimit) {
13501360
RECURSION_DEPTH_LIMIT = newRecursionDepthLimit;
13511361
}
@@ -1355,6 +1365,16 @@ public void setRecursionDepthLimit(int newRecursionDepthLimit) {
13551365
* value is 500
13561366
* @return the recursion depth limit
13571367
*/
1368+
public static int getGlobalRecursionDepthLimit() {
1369+
return RECURSION_DEPTH_LIMIT;
1370+
}
1371+
1372+
/**
1373+
* Get the new recursion depth limit to prevent stack overflow issues on deeply nested structures. The default
1374+
* value is 500
1375+
* @return the recursion depth limit
1376+
*/
1377+
@Deprecated
13581378
public int getRecursionDepthLimit() {
13591379
return RECURSION_DEPTH_LIMIT;
13601380
}

src/test/java/org/codehaus/jettison/json/JSONArrayTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void testInfiniteLoop2() {
6565
}
6666

6767
public void testIssue52() throws JSONException {
68-
new JSONObject().setRecursionDepthLimit(10);
68+
JSONObject.setGlobalRecursionDepthLimit(10);
6969
new JSONArray("[{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {a:10}]");
7070
}
7171

0 commit comments

Comments
 (0)