Repository navigation
Share modified UTF-8 codec across classfile and data streams - #214
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #214 +/- ##
=======================================
Coverage 87.19% 87.20%
=======================================
Files 308 309 +1
Lines 46374 46332 -42
=======================================
- Hits 40437 40403 -34
+ Misses 5937 5929 -8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🔵 Needs a closer look
It changes the core class-file constant-pool parsing path and intentionally drops a previously-accepted encoding (standard 4-byte UTF-8), so a human should confirm that acceptance-behavior change is acceptable.
0 open findings
What changed in this PR
This PR removes three separate, hand-rolled modified UTF-8 implementations and replaces them with a single shared codec in the jvm-types crate. Previously, classfile constant-pool parsing, DataInputStream.readUTF, and DataOutputStream.writeUTF each had their own encode/decode logic; this centralizes them into jvm_types::modified_utf8 (operating on UTF-16 code units, no_std/alloc), reducing duplication and aligning behavior across the class loader and stream APIs.
Changes:
- Add
jvm_types::modified_utf8withencode(&[u16]) -> Vec<u8>anddecode(&[u8]) -> Option<Vec<u16>>, preserving unpaired surrogates and rejecting malformed input; makejvm-types#![no_std]withextern crate alloc. - Reuse the codec in
classfileparsing (now intentionally rejecting standard 4‑byte UTF‑8) and inDataInputStream.readUTF/DataOutputStream.writeUTF, keeping the stream exceptions and 65,535-byte length limit. - Expand tests for exact encoded bytes, unpaired surrogates, malformed sequences, and the encoded-length limit.
| File | Description |
|---|---|
jvm-types/src/modified_utf8.rs |
New shared modified UTF-8 encode/decode over UTF-16 code units. |
jvm-types/src/lib.rs |
Makes crate #![no_std], adds alloc, exposes modified_utf8 module. |
classfile/src/constant_pool.rs |
Replaces inline decoder with shared codec; drops the 4-byte compatibility path; updates tests. |
rustjava-runtime/src/classes/java/io/data_input_stream.rs |
readUTF now decodes via the shared codec. |
rustjava-runtime/src/classes/java/io/data_output_stream.rs |
writeUTF now encodes via the shared codec. |
rustjava-runtime/tests/classes/java/io/test_data_output_stream.rs |
Expands round-trip, malformed-input, and length-limit coverage. |
I verified the encode/decode logic against the test vectors (all 12 code units, the 27-byte encoded length, NUL→C0 80, surrogate handling, and every malformed case), confirmed jvm-types has no std:: usage so the #![no_std] switch is safe, confirmed the removed imports (Vec, REPLACEMENT_CHARACTER) are no longer referenced, and confirmed no leftover callers of the old decode_modified_utf8. No objective issues were found.
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Changes
jvm-types, usingno_stdandalloc.DataInputStream.readUTF/DataOutputStream.writeUTF, preserving stream exceptions and encoded-length limits.Verification
cargo test --workspacepassed (two existing ignored tests).cargo clippy --workspace --all-targets -- -D warningspassed.cargo fmt --all -- --checkpassed.cargo check -p jvm-types -p classfile -p rustjava-runtime --lib --target wasm32-unknown-unknownpassed.test-utilsTokiort-multi-threadfeature.