Use IdentityHashSet for cycle detection

Fixes https://github.com/stleary/JSON-java/issues/650
This commit is contained in:
Liam Miller-Cushon
2021-11-26 20:07:21 -05:00
parent bc623e36d6
commit 812955e39d
3 changed files with 52 additions and 2 deletions

View File

@@ -74,6 +74,7 @@ import org.json.junit.data.MyNumber;
import org.json.junit.data.MyNumberContainer;
import org.json.junit.data.MyPublicClass;
import org.json.junit.data.RecursiveBean;
import org.json.junit.data.RecursiveBeanEquals;
import org.json.junit.data.Singleton;
import org.json.junit.data.SingletonEnum;
import org.json.junit.data.WeirdList;
@@ -3311,6 +3312,21 @@ public class JSONObjectTest {
new JSONObject(ObjD);
new JSONObject(ObjE);
}
@Test(expected=JSONException.class)
public void testRecursiveEquals() {
RecursiveBeanEquals a = new RecursiveBeanEquals("same");
a.setRef(a);
new JSONObject(a);
}
@Test
public void testNotRecursiveEquals() {
RecursiveBeanEquals a = new RecursiveBeanEquals("same");
RecursiveBeanEquals b = new RecursiveBeanEquals("same");
RecursiveBeanEquals c = new RecursiveBeanEquals("same");
a.setRef(b);
b.setRef(c);
new JSONObject(a);
}
@Test