Skip to content

Commit 75a784f

Browse files
wenshaoclaude
andcommitted
test: extend Issue7616 with multi-field and split-group coverage
- Multi-field UTF-16: ensures the per-field stringCapacity stays in sync with the BC_OBJECT/BC_OBJECT_END framing accounting. - Split-group bean: exercises the (group.start=false, group.end=false) middle-direct-group code path that the inverted formula previously over-allocated by 2 bytes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7d5d15c commit 75a784f

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

core/src/test/java/com/alibaba/fastjson2/issues_7000/Issue7616.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,58 @@ public static class Message {
2222
public String payload;
2323
}
2424

25+
public static class MultiField {
26+
public String a;
27+
public String b;
28+
public String c;
29+
}
30+
31+
@Test
32+
public void testLargeUtf16MultiField() {
33+
// Three fields whose UTF-16 capacities are tightly packed; the previous
34+
// off-by-two in BC_OBJECT/BC_OBJECT_END accounting failed here too.
35+
MultiField mf = new MultiField();
36+
mf.a = repeat('\u4E00', 100000);
37+
mf.b = repeat('\u4E01', 100000);
38+
mf.c = repeat('\u4E02', 100000);
39+
byte[] bytes = JSONB.toBytes(mf);
40+
MultiField parsed = JSONB.parseObject(bytes, MultiField.class);
41+
assertEquals(mf.a, parsed.a);
42+
assertEquals(mf.b, parsed.b);
43+
assertEquals(mf.c, parsed.c);
44+
}
45+
46+
public static class Inner {
47+
public int x;
48+
}
49+
50+
public static class SplitGroupBean {
51+
public Inner head; // non-direct (Bean)
52+
public String middle; // direct (String)
53+
public Inner tail; // non-direct (Bean)
54+
}
55+
56+
@Test
57+
public void testSplitGroupWithDirectMiddle() {
58+
SplitGroupBean b = new SplitGroupBean();
59+
b.head = new Inner();
60+
b.head.x = 1;
61+
b.middle = repeat('\u4E00', 50000);
62+
b.tail = new Inner();
63+
b.tail.x = 2;
64+
byte[] bytes = JSONB.toBytes(b);
65+
SplitGroupBean parsed = JSONB.parseObject(bytes, SplitGroupBean.class);
66+
assertEquals(b.head.x, parsed.head.x);
67+
assertEquals(b.middle, parsed.middle);
68+
assertEquals(b.tail.x, parsed.tail.x);
69+
}
70+
71+
private static String repeat(char ch, int n) {
72+
char[] arr = new char[n];
73+
java.util.Arrays.fill(arr, ch);
74+
return new String(arr);
75+
}
76+
2577
@Test
2678
public void testLargeUtf16StringInNestedBean() {
2779
int len = 232768;

0 commit comments

Comments
 (0)