Skip to content

Share modified UTF-8 codec across classfile and data streams - #214

Merged
dlunch merged 2 commits into
mainfrom
refactor/shared-modified-utf8
Oct 14, 2026
Merged

dlunch merged 2 commits into
mainfrom
refactor/shared-modified-utf8

Conversation

@dlunch

@dlunch dlunch commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Changes

  • Centralize UTF-16-based modified UTF-8 encoding and decoding in jvm-types, using no_std and alloc.
  • Reuse the codec in classfile parsing and DataInputStream.readUTF / DataOutputStream.writeUTF, preserving stream exceptions and encoded-length limits.
  • Reject standard four-byte UTF-8 in classfile constants instead of retaining the previous compatibility path.
  • Extend tests for exact encoded bytes, unpaired surrogates, malformed sequences, and the 65,535-byte output limit.

Verification

  • cargo test --workspace passed (two existing ignored tests).
  • cargo clippy --workspace --all-targets -- -D warnings passed.
  • cargo fmt --all -- --check passed.
  • cargo check -p jvm-types -p classfile -p rustjava-runtime --lib --target wasm32-unknown-unknown passed.
  • Full-workspace WebAssembly checking is blocked by the existing test-utils Tokio rt-multi-thread feature.

Copilot AI balanced review requested due to automatic review settings October 14, 2026 03:59
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T04:05:57.971687Z c8cc5d4 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.20%. Comparing base (a83ced6) to head (c8cc5d4).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 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_utf8 with encode(&[u16]) -> Vec<u8> and decode(&[u8]) -> Option<Vec<u16>>, preserving unpaired surrogates and rejecting malformed input; make jvm-types #![no_std] with extern crate alloc.
  • Reuse the codec in classfile parsing (now intentionally rejecting standard 4‑byte UTF‑8) and in DataInputStream.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.

@dlunch
dlunch merged commit 5e9360a into main Oct 14, 2026
14 checks passed
@dlunch
dlunch deleted the refactor/shared-modified-utf8 branch October 14, 2026 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants