You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While writing a test case for circular reference serialization, I discovered that the current implementation of JsonWriter does not handle circular references properly, leading to a StackOverflowError.
@TestpublicvoidtestCircularReferenceSerialization() {
// Create a dictionary and introduce a circular reference by setting one of its values to be the dictionary itself.JsonObjectdict = newJsonObject(16, 0.75f);
dict.put("a", dict);
// Attempt to serialize the dictionary using a JSON serialization method.JsonWriterjsonWriter = newJsonWriter();
try {
jsonWriter.string(dict);
fail("Expected a ValueError indicating the presence of a circular reference.");
} catch (IllegalArgumentExceptione) {
assertTrue(e.getMessage().contains("circular reference"), "The exception message should indicate a circular reference.");
}
}
Expected Behavior:
The JsonWriter should detect the circular reference and throw an IllegalArgumentException with a message indicating the presence of a circular reference.
Actual Behavior:
The JsonWriter enters an infinite recursion due to the circular reference, resulting in a StackOverflowError.
Proposed Solution:
To handle circular references, the JsonWriter (or its base class, JsonWriterBase) should implement a mechanism to track visited objects during serialization. If a circular reference is detected, an exception should be thrown to prevent infinite recursion.
The text was updated successfully, but these errors were encountered:
testmigrator
changed the title
Title: NullPointerException (NPE) due to circular reference in JsonWriter serialization
Circular Reference Causes StackOverflowError in JsonWriter
Mar 6, 2025
While writing a test case for circular reference serialization, I discovered that the current implementation of JsonWriter does not handle circular references properly, leading to a
StackOverflowError
.Expected Behavior:
The JsonWriter should detect the circular reference and throw an IllegalArgumentException with a message indicating the presence of a circular reference.
Actual Behavior:
The JsonWriter enters an infinite recursion due to the circular reference, resulting in a StackOverflowError.
Proposed Solution:
To handle circular references, the JsonWriter (or its base class, JsonWriterBase) should implement a mechanism to track visited objects during serialization. If a circular reference is detected, an exception should be thrown to prevent infinite recursion.
The text was updated successfully, but these errors were encountered: