Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/src/main/java/com/alibaba/fastjson2/JSONReaderASCII.java
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,9 @@ public final String readFieldName() {
int c = bytes[offset];
if (c == '\\') {
nameEscape = true;
if (offset + 1 >= end) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] Nothing in the test suite pins this guard: reverting all three added lines leaves the entire reactor suite green. Measured during this review — the full 15-module mvn test on the PR reports 9606 tests / 0 failures, and the same suite on an identical tree with only these three lines reverted (the file restored to 30dd009d1) reports the exact same 9606 / 0 failures. The behavioral delta is real, though: with the guard, JSON.parseObject("{\"a\\") throws JSONException: illegal input; with it reverted, the same call throws ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4. readFieldName() is a large method that gets hot-path refactors regularly, so a future edit that drops this branch would silently resurrect the original #7809 symptom — an unchecked ArrayIndexOutOfBoundsException escaping callers' catch (JSONException) — with no CI signal. Suggest adding core/src/test/java/com/alibaba/fastjson2/issues_7000/Issue7809.java (the convention used by the sibling fixes Issue7668/7678/7691): assertThrows(JSONException.class, () -> JSON.parseObject("{\"a\\")) for the inputs {"\, {"a\ and {"a":1,"b\ — asserting the specific type matters here, since ArrayIndexOutOfBoundsException is also a RuntimeException and a loose assertThrows(Exception.class, ...) would stay green on the unfixed build — plus one positive control such as {"a\"b":1} still parsing to key a"b. As the acceptance criterion for that new test, remove these three lines and confirm it goes red with the ArrayIndexOutOfBoundsException.

— qwen3.8-flash via Qwen Code /review (v0.22.2)

throw new JSONException(info("illegal input"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] The new throw diverges from this file's established wording for the same condition. JSONReaderASCII already reports "escape ran off the end" as error("invalid escape character EOI") at six sites (lines 147, 213, 284, 546, 1269, 1398), and JSONReader.error(String) is exactly new JSONException(info(message)) — so the added line hand-inlines that factory with a different message, and the commit's stated rationale ("matching how malformed field names are handled elsewhere") does not hold. Measured on this commit: JSON.parseObject("{\"a\\") (Map path) now reports illegal input, offset 2 while JSON.parseObject("{\"a\\", Foo.class) (bean path, line 147) reports invalid escape character EOI, offset 2 for the same one-line document — tests or alert rules that match the established string (16 call sites across core) will not recognize the new branch. Suggest reusing the factory: ```suggestion throw error("invalid escape character EOI"); ``` No test asserts illegal input today (grep over core/src/test returns nothing), so the swap contradicts nothing; and if the UTF16 twin at JSONReaderUTF16.java:1991 gets the same guard in a follow-up, it is worth choosing the wording once for both readers.

— qwen3.8-flash via Qwen Code /review (v0.22.2)

}
c = bytes[offset + 1];
offset += (c == 'u' ? 6 : (c == 'x' ? 4 : 2));
continue;
Expand Down
Loading