Skip to content

Commit

Permalink
Fixing StackOverflow error
Browse files Browse the repository at this point in the history
  • Loading branch information
coheigea committed Nov 16, 2022
1 parent 325b51b commit f9b4c79
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/codehaus/jettison/json/JSONObject.java
Expand Up @@ -268,7 +268,7 @@ public JSONObject(Map map) {
if (v instanceof Collection) {
myHashMap.put(entry.getKey(), new JSONArray((Collection) v));
}
if (v instanceof Map) {
if (v instanceof Map && v != map) {
myHashMap.put(entry.getKey(), new JSONObject((Map) v));
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/codehaus/jettison/json/JSONObjectTest.java
Expand Up @@ -2,6 +2,11 @@

import junit.framework.TestCase;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JSONObjectTest extends TestCase {
public void testEquals() throws Exception {
JSONObject aJsonObj = new JSONObject("{\"x\":\"y\"}");
Expand Down Expand Up @@ -148,4 +153,10 @@ public void testMalformedArray() throws Exception {
}
}

// https://github.com/jettison-json/jettison/issues/52
public void testIssue52() throws Exception {
Map<String,Object> map = new HashMap<>();
map.put("t",map);
new JSONObject(map);
}
}

0 comments on commit f9b4c79

Please sign in to comment.