You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fory.apache.org by "pavel-ptashyts (via GitHub)" <gi...@apache.org> on 2026/09/30 12:11:08 UTC

[PR] fix(java): keep JSON string writer prefix field names unique past 160 properties [fory]

pavel-ptashyts opened a new pull request, #4099:
URL: https://github.com/apache/fory/pull/4099

   ## Why?
   
   The generated JSON string writer fails to load for a type with 161 or more properties: `ClassFormatError: Duplicate field name "s160"`. With synchronous compilation every operation on such a type throws (including `toJsonBytes` and `fromJson`, since the string writer is built with the type's codec graph); with the default asynchronous compilation the failure is silent and the type stays on the interpreted codec for good.
   
   ## What does this PR do?
   
   `StringWriterCodegen` names its per-property prefix fields from the property index: `"s" + id` / `"sc" + id` for Latin1 and `"s16" + id` / `"sc16" + id` for UTF-16. `"s" + 160` and `"s16" + 0` are both `s160` (and `"sc" + 160` / `"sc16" + 0` both `sc160`). This PR adds a separator to the UTF-16 names, `"s16_" + id` / `"sc16_" + id`, at the declaration (`addPrefixFields`) and at the only reference (`utf16PrefixRef`). The other generated field names in the JSON writers and readers (`s`, `sc`, `u`, `uc`, `w`, `wp`, `r`, `rp`, `o`, `p`, ...) are letters followed by the index, so they cannot collide this way.
   
   Regression test `JsonGeneratedCodecTest#writeGeneratedFieldsPastPrefixIndexCollision` compiles a 161-property model with Janino, writes it with a non-Latin1 character in the first value so the string writer takes the UTF-16 prefix path, and checks `toJson`, `toJsonBytes`, `fromJson` and that the type has generated codecs. It fails on main with the `ClassFormatError` above and passes with the fix.
   
   ## Related issues
   
   Closes #4094
   
   ## AI Contribution Checklist
   
   - [x] Substantial AI assistance was used in this PR: `yes`
   - [x] If `yes`, I included a completed [AI Contribution Checklist](https://github.com/apache/fory/blob/main/AI_POLICY.md#9-contributor-checklist-for-ai-assisted-prs) in this PR description and the required `AI Usage Disclosure`.
   - [x] If `yes`, my PR description includes the required `ai_review` summary and screenshot evidence or equivalent persisted links of the final clean AI review results from both fresh reviewers described in `AI_POLICY.md`, the Fory-guided reviewer and the independent general reviewer, on the current PR diff or current HEAD after the latest code changes.
   
   - [x] I can explain and defend all important changes without AI help.
   - [x] I reviewed AI-assisted code changes line by line before submission.
   - [x] I completed line-by-line self-review first and fixed issues before requesting AI review.
   - [x] I ran two fresh AI review agents on the current HEAD: one Fory-guided reviewer using `AGENTS.md` and `.agents/ci-and-pr.md`, and one independent general reviewer in a separate clean-context session that was not pointed to `.agents/ci-and-pr.md`; it auto-loaded `AGENTS.md` and followed the independent-review carve-out.
   - [x] I addressed all AI review comments and repeated the review loop until both reviewers reported no further actionable comments.
   - [x] I attached equivalent persisted links of the final clean AI review results from both reviewers on the current HEAD.
   - [x] I ran adequate human verification and recorded evidence.
   - [x] I added tests where required.
   - [x] I validated protocol/performance impacts with evidence when applicable.
   - [x] I verified licensing and provenance compliance.
   
   ```text
   AI Usage Disclosure
   - substantial_ai_assistance: yes
   - scope: code drafting, tests
   - affected_files_or_subsystems: java/fory-json codegen (StringWriterCodegen), java/fory-json tests (JsonGeneratedCodecTest)
   - ai_review: line-by-line self-review completed; Fory-guided reviewer (Codex, AGENTS.md + .agents/ci-and-pr.md) and independent general reviewer (Claude Code, clean session, independent-review carve-out) both reviewed HEAD 5ac69d0d against main 14039c4a and both reported NO FURTHER ACTIONABLE COMMENTS (an earlier pass on 33c1e0b2 was clean as well; the only change since is the test literal written as an \u0100 escape)
   - ai_review_artifacts: https://gist.github.com/pavel-ptashyts/d483b8788c5417264c7a99a0e4197098 (prompts and full outputs of both reviewers; the verdict is at the end of each log)
   - human_verification: from java/: `mvn -pl fory-json -am install -DskipTests`, then `mvn -pl fory-json test` -> Tests run: 1269, Failures: 0, Errors: 0, Skipped: 0 (after the final test-literal change `-Dtest=JsonGeneratedCodecTest` -> 28 run, 0 failures); the new test fails on main with ClassFormatError: Duplicate field name "s160" before the fix; `mvn -pl fory-json spotless:check` and `checkstyle:check` -> BUILD SUCCESS; JDK 25.0.2, Windows 11; results reviewed
   - performance_verification: N/A - only the names of generated fields change; generated code shape and the hot path are unchanged
   - provenance_license_confirmation: Apache-2.0-compatible provenance confirmed; no third-party code introduced
   ```
   
   ## Does this PR introduce any user-facing change?
   
   - [ ] Does this PR introduce any public API change?
   - [ ] Does this PR introduce any binary protocol compatibility change?
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): keep JSON string writer prefix field names unique past 160 properties [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang merged PR #4099:
URL: https://github.com/apache/fory/pull/4099


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org