Skip to content

Bug: StackOverflow in toString() (infinite recursion) #148

@kmnls

Description

@kmnls

Minimal reproducible example:

import org.json.simple.JSONObject;

public class Test {
    public static void main(String[] args) throws Exception {

        JSONObject obj1=new JSONObject();
        obj1.put("",obj1);
        obj1.toString();
     }
}

Description:

Converting invalid JSONObject to String will result in stack overflow.

Log:

Exception in thread "main" java.lang.StackOverflowError
at org.json.simple.JSONObject.writeJSONString(JSONObject.java:55)
at org.json.simple.JSONObject.writeJSONString(JSONObject.java:74)
at org.json.simple.JSONValue.writeJSONString(JSONValue.java:160)
at org.json.simple.JSONObject.writeJSONString(JSONObject.java:68)
at org.json.simple.JSONObject.writeJSONString(JSONObject.java:74)
at org.json.simple.JSONValue.writeJSONString(JSONValue.java:160)
at org.json.simple.JSONObject.writeJSONString(JSONObject.java:68)
at org.json.simple.JSONObject.writeJSONString(JSONObject.java:74)
at org.json.simple.JSONValue.writeJSONString(JSONValue.java:160)
at org.json.simple.JSONObject.writeJSONString(JSONObject.java:68)
at org.json.simple.JSONObject.writeJSONString(JSONObject.java:74)
at org.json.simple.JSONValue.writeJSONString(JSONValue.java:160)
at org.json.simple.JSONObject.writeJSONString(JSONObject.java:68)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions