-
Notifications
You must be signed in to change notification settings - Fork 575
fix: JSONB ASM direct-write skips level tracking causing false 'level too large' on flat lists, for issue #3616 #7635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
daguimu
wants to merge
1
commit into
alibaba:main
Choose a base branch
from
daguimu:fix/asm-jsonb-level-tracking-3616
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+136
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
108 changes: 108 additions & 0 deletions
108
core/src/test/java/com/alibaba/fastjson2/issues_3600/Issue3616.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package com.alibaba.fastjson2.issues_3600; | ||
|
|
||
| import com.alibaba.fastjson2.JSONB; | ||
| import org.junit.jupiter.api.Tag; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.math.BigDecimal; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| @Tag("regression") | ||
| public class Issue3616 { | ||
| /** | ||
| * Issue #3616: a flat list of JavaBeans whose field groups split between the | ||
| * direct-write path (e.g. String) and the non-direct-write path (e.g. BigDecimal) | ||
| * caused {@code JSONException: level too large} after ~2049 elements, even though | ||
| * the structure has no real nesting. Each bean called {@code startObject()} | ||
| * (level++) but the matching object end was emitted as a raw byte on the direct | ||
| * path, so {@code level} never decremented. | ||
| */ | ||
| @Test | ||
| public void testFlatListBigDecimalAndString() { | ||
| List<MixedBean> list = new ArrayList<>(); | ||
| for (int i = 0; i < 2100; i++) { | ||
| list.add(new MixedBean("a" + i, new BigDecimal("1232132"))); | ||
| } | ||
|
|
||
| byte[] bytes = assertDoesNotThrow(() -> JSONB.toBytes(list)); | ||
| List<MixedBean> parsed = JSONB.parseArray(bytes, MixedBean.class); | ||
| assertEquals(list.size(), parsed.size()); | ||
| assertEquals("a0", parsed.get(0).getD()); | ||
| assertEquals(new BigDecimal("1232132"), parsed.get(0).getC()); | ||
| assertEquals("a2099", parsed.get(2099).getD()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFlatListWithDateObject() { | ||
| List<DateBean> list = new ArrayList<>(); | ||
| for (int i = 0; i < 2100; i++) { | ||
| list.add(new DateBean("name" + i, new java.util.Date(0))); | ||
| } | ||
| assertDoesNotThrow(() -> JSONB.toBytes(list)); | ||
| } | ||
|
|
||
| public static class MixedBean implements Serializable { | ||
| private static final long serialVersionUID = 1L; | ||
| private String d; | ||
| private BigDecimal c; | ||
|
|
||
| public MixedBean() { | ||
| } | ||
|
|
||
| public MixedBean(String d, BigDecimal c) { | ||
| this.d = d; | ||
| this.c = c; | ||
| } | ||
|
|
||
| public String getD() { | ||
| return d; | ||
| } | ||
|
|
||
| public void setD(String d) { | ||
| this.d = d; | ||
| } | ||
|
|
||
| public BigDecimal getC() { | ||
| return c; | ||
| } | ||
|
|
||
| public void setC(BigDecimal c) { | ||
| this.c = c; | ||
| } | ||
| } | ||
|
|
||
| public static class DateBean implements Serializable { | ||
| private static final long serialVersionUID = 1L; | ||
| private String name; | ||
| private java.util.Date time; | ||
|
|
||
| public DateBean() { | ||
| } | ||
|
|
||
| public DateBean(String name, java.util.Date time) { | ||
| this.name = name; | ||
| this.time = time; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public void setName(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public java.util.Date getTime() { | ||
| return time; | ||
| } | ||
|
|
||
| public void setTime(java.util.Date time) { | ||
| this.time = time; | ||
| } | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion]
testFlatListWithDateObjectonly asserts that serialization does not throw; it never deserializes or verifies field content, unliketestFlatListBigDecimalAndStringwhich does a full round-trip. — Concrete cost: a regression that produces structurally valid-but-wrong JSONB bytes for the Date+String split would pass this test silently.— qwen3-coder via Qwen Code /review