Skip to content

Commit

Permalink
Introducing new static methods to set the recursion depth limit
Browse files Browse the repository at this point in the history
  • Loading branch information
coheigea committed Dec 5, 2022
1 parent 888eec8 commit d9da808
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/main/java/org/codehaus/jettison/json/JSONObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,16 @@ static String valueToString(Object value, int indentFactor, int indent, boolean
* value is 500
* @param newRecursionDepthLimit the new recursion depth limit to set
*/
public static void setGlobalRecursionDepthLimit(int newRecursionDepthLimit) {
RECURSION_DEPTH_LIMIT = newRecursionDepthLimit;
}

/**
* Set the new recursion depth limit to prevent stack overflow issues on deeply nested structures. The default
* value is 500
* @param newRecursionDepthLimit the new recursion depth limit to set
*/
@Deprecated
public void setRecursionDepthLimit(int newRecursionDepthLimit) {
RECURSION_DEPTH_LIMIT = newRecursionDepthLimit;
}
Expand All @@ -1355,6 +1365,16 @@ public void setRecursionDepthLimit(int newRecursionDepthLimit) {
* value is 500
* @return the recursion depth limit
*/
public static int getGlobalRecursionDepthLimit() {
return RECURSION_DEPTH_LIMIT;
}

/**
* Get the new recursion depth limit to prevent stack overflow issues on deeply nested structures. The default
* value is 500
* @return the recursion depth limit
*/
@Deprecated
public int getRecursionDepthLimit() {
return RECURSION_DEPTH_LIMIT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void testInfiniteLoop2() {
}

public void testIssue52() throws JSONException {
new JSONObject().setRecursionDepthLimit(10);
JSONObject.setGlobalRecursionDepthLimit(10);
new JSONArray("[{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {a:10}]");
}

Expand Down

0 comments on commit d9da808

Please sign in to comment.