fix: prevent StackOverflowError in ObjectView JSON mode for circular references#3160
Open
daguimu wants to merge 1 commit intoalibaba:masterfrom
Open
fix: prevent StackOverflowError in ObjectView JSON mode for circular references#3160daguimu wants to merge 1 commit intoalibaba:masterfrom
daguimu wants to merge 1 commit intoalibaba:masterfrom
Conversation
4bf05c8 to
b19886f
Compare
…references When watch command uses JSON format (options json true), fastjson2 serialization can enter infinite recursion on objects with circular references or deeply nested object graphs, causing StackOverflowError. Fix by adding JSONWriter.Feature.ReferenceDetection to detect and break circular references using JSON $ref syntax, and catch StackOverflowError as a safety net with a user-friendly error message. Fixes alibaba#3095
b19886f to
12d3b50
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using
watchcommand with JSON output mode (options json true), fastjson2 serialization causesStackOverflowErroron objects with circular references or deeply nested object graphs.Stack trace example from issue #3095:
Fix
JSONWriter.Feature.ReferenceDetectionto detect circular references and serialize them using JSON$refsyntax instead of infinite recursionStackOverflowErroras a safety net and return a user-friendly error message with a hint to disable json mode (options json false)Test
Added unit test
testJsonModeCircularReferencethat creates a circular reference (A→B→A) and verifies no exception is thrown.Fixes #3095