Repository navigation
fix: use createReadContext for string reparse in fastjson1-compatible, for issue #7765 - #7767
Conversation
wenshao
left a comment
There was a problem hiding this comment.
Reviewed — no blockers. Suggestions are inline.
中文说明
已审查——无阻断问题。 建议见行内评论。
— glm-5.2 via Qwen Code /review (v0.21.10)
….of sites, for issue alibaba#7765
|
Thanks for the review — all three suggestions addressed.
中文说明感谢 review,三条建议都已处理:
|
wenshao
left a comment
There was a problem hiding this comment.
Reviewed. Suggestions are inline. 1 Suggestion-level finding(s) could not be anchored to a changed line and were dropped; nothing further to act on here.
Not explored to full depth (tool budget reached): "本 PR 修复 fastjson1-compatible 的 issue…": did not compile the changed classes for static bytecode-size measurement (javap tier) — the ~6–8-byte growth per modified method was assessed by inspection agai…; "本 PR 修复 fastjson1-compatible 的 issue…": none — I did not run mvn test (worktree shared with concurrent agents), relying on static verification of signatures/overloads instead.; "本 PR 修复 fastjson1-compatible 的 issue…": did not execute mvn test -Dtest=Issue7765 — the worktree is shared with concurrently running review agents, so a Maven build in place risks racing their work;…; "本 PR 修复 fastjson1-compatible 的 issue…": did not compile/run the module tests — the worktree has no pre-built target/classes and building via Maven in a shared worktree is prohibited for this review;…; "本 PR 修复 fastjson1-compatible 的 issue…": no bytecode-size measurement (static tier needs a compile; no pre-built classpath) — not pursued because the per-method structural delta is a single invokestati…, and 4 more.
中文说明
已审查。 建议见行内评论。 1 条建议级发现无法锚定到改动行,已丢弃;此处无需进一步处理。
未探索到全部深度(达到工具调用预算):"本 PR 修复 fastjson1-compatible 的 issue…":did not compile the changed classes for static bytecode-size measurement (javap tier) — the ~6–8-byte growth per modified method was assessed by inspection agai…;"本 PR 修复 fastjson1-compatible 的 issue…":none — I did not run mvn test (worktree shared with concurrent agents), relying on static verification of signatures/overloads instead.;"本 PR 修复 fastjson1-compatible 的 issue…":did not execute mvn test -Dtest=Issue7765 — the worktree is shared with concurrently running review agents, so a Maven build in place risks racing their work;…;"本 PR 修复 fastjson1-compatible 的 issue…":did not compile/run the module tests — the worktree has no pre-built target/classes and building via Maven in a shared worktree is prohibited for this review;…;"本 PR 修复 fastjson1-compatible 的 issue…":no bytecode-size measurement (static tier needs a compile; no pre-built classpath) — not pursued because the per-method structural delta is a single invokestati…,另有 4 条。
— qwen3.8-max via Qwen Code /review (v0.21.11)
wenshao
left a comment
There was a problem hiding this comment.
No issues found. LGTM! ✅
中文说明
未发现问题。LGTM!✅
— glm-5.3 via Qwen Code /review (v0.21.11)
Resolve the conflict with alibaba#7767, which refactored the same three files: * JSON.createReadContext(Feature...) is kept as added upstream; * JSONPath.read(String, String, Type, ParserConfig) keeps JSON.createReadContext() and only flips SupportAutoType on top of it; * DefaultJSONParser builds its reader from JSON.createReadContext() and only flips SupportAutoType when the ParserConfig asks for it. The resulting diff against main is the auto type gating alone.
Resolve the conflict with alibaba#7767, which refactored the same three files: * JSON.createReadContext(Feature...) is kept as added upstream; * JSONPath.read(String, String, Type, ParserConfig) keeps JSON.createReadContext() and only flips SupportAutoType on top of it; * DefaultJSONParser builds its reader from JSON.createReadContext() and only flips SupportAutoType when the ParserConfig asks for it. The resulting diff against main is the auto type gating alone.
What this PR does / why we need it?
Fixes #7765.
In fastjson1-compatible mode, when a field value is a JSON string and is re-parsed by
getJSONArray/getJSONObject/getObject, nested containers could becomecom.alibaba.fastjson2.JSONObject/JSONArray. Casting them tocom.alibaba.fastjson.JSONObjectthen throwsClassCastException.Root cause: those paths used bare
JSONReader.of(...)and skippedJSON.createReadContext(...), soobjectSupplier/arraySupplierwere not applied.Summary of your change
Use
JSON.createReadContext(JSON.DEFAULT_PARSER_FEATURE)for string reparse in:JSONObject.getJSONObject(String)/getJSONArray(String)/getObject(String, TypeReference)JSONArray.getJSONObject(int)/getJSONArray(int)/getObject(int, Class)Add regression tests in
Issue7765.中文说明
这个 PR 做了什么 / 为什么需要?
修复 #7765。
fastjson1 兼容模式下,字段值是 JSON 字符串时,经 getJSONArray / getJSONObject / getObject 二次解析后,嵌套容器可能变成 com.alibaba.fastjson2.JSONObject / JSONArray,再强转为 com.alibaba.fastjson.JSONObject 会抛 ClassCastException。
根因:这些路径使用了裸的 JSONReader.of(...),未走 JSON.createReadContext(...),因此未注入 objectSupplier / arraySupplier。
变更摘要
上述 6 处二次解析改为使用 JSON.createReadContext(JSON.DEFAULT_PARSER_FEATURE)
新增 Issue7765 回归测试
Please indicate you've done the following: