The cycle detection introduced in #632 / #645 doesn't handle cycles that involved collections. The following example still results in a StackOverflowError:
import java.util.Collections;
import java.util.List;
import org.json.JSONObject;
class Json {
public static void main(String[] args) {
new JSONObject(new Foo());
}
public static class Foo {
public List<Foo> getFoos() {
return Collections.singletonList(this);
}
}
}
Exception in thread "main" java.lang.StackOverflowError
at org.json.JSONObject.getKeyNameFromMethod(JSONObject.java:1591)
at org.json.JSONObject.populateMap(JSONObject.java:1548)
at org.json.JSONObject.populateMap(JSONObject.java:1529)
at org.json.JSONObject.<init>(JSONObject.java:366)
at org.json.JSONObject.wrap(JSONObject.java:2499)
at org.json.JSONObject.wrap(JSONObject.java:2457)
at org.json.JSONArray.addAll(JSONArray.java:1609)
at org.json.JSONArray.<init>(JSONArray.java:176)
at org.json.JSONObject.wrap(JSONObject.java:2478)
at org.json.JSONObject.populateMap(JSONObject.java:1563)
at org.json.JSONObject.populateMap(JSONObject.java:1529)
at org.json.JSONObject.<init>(JSONObject.java:366)
The cycle detection introduced in #632 / #645 doesn't handle cycles that involved collections. The following example still results in a
StackOverflowError: