Skip to content

Fix runtime null handling and standard stream initialization - #226

Merged
dlunch merged 1 commit into
mainfrom
fix/runtime-null-handling
Oct 24, 2026
Merged

dlunch merged 1 commit into
mainfrom
fix/runtime-null-handling

Conversation

@dlunch

@dlunch dlunch commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Changes

  • Enforce Java null contracts across String, array copying, exception output, numeric decoding, class loaders, URL connections, and ZIP/JAR APIs without Rust panics.
  • Validate I/O arguments and nullable backing streams while preserving valid empty operations. Keep standard file descriptors non-null when host streams are unavailable, reporting IOException on use.
  • Preserve nullable calendar/date-format setters and handle subsequent operations safely, including numeric parsing and literal-only input.
  • Add integration regressions for rejected and permitted null inputs, empty operations, and recovery from nullable state.

Verification

  • Workspace tests: 577 passed, 2 ignored.
  • Native all-targets and wasm32-unknown-unknown Clippy checks passed with warnings denied.
  • Formatting and diff checks passed.

Wasm execution was not tested.

Copilot AI balanced review requested due to automatic review settings October 24, 2026 09:48
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 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-24T09:49:16.080616Z 11973e4 PR opened
ℹ️ 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 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.55583% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.78%. Comparing base (a848a99) to head (11973e4).

Files with missing lines Patch % Lines
...untime/src/classes/java/text/simple_date_format.rs 72.72% 15 Missing ⚠️
...runtime/src/classes/java/io/filter_input_stream.rs 86.11% 5 Missing ⚠️
...-runtime/src/classes/java/io/data_output_stream.rs 94.54% 3 Missing ⚠️
...untime/src/classes/java/io/filter_output_stream.rs 86.36% 3 Missing ⚠️
...a-runtime/src/classes/java/io/data_input_stream.rs 95.00% 1 Missing ⚠️
...-runtime/src/classes/java/io/random_access_file.rs 94.44% 1 Missing ⚠️
...ustjava-runtime/src/classes/java/lang/throwable.rs 83.33% 1 Missing ⚠️
...tjava-runtime/src/classes/java/text/date_format.rs 94.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #226      +/-   ##
==========================================
+ Coverage   87.31%   87.78%   +0.46%     
==========================================
  Files         311      311              
  Lines       46772    47092     +320     
==========================================
+ Hits        40841    41338     +497     
+ Misses       5931     5754     -177     

☔ 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.

@dlunch
dlunch merged commit ca4412f into main Oct 24, 2026
15 checks passed
@dlunch
dlunch deleted the fix/runtime-null-handling branch October 24, 2026 09:51

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

The change spans ~40 files and alters cross-cutting runtime semantics (standard stream initialization and multiple Java exception contracts), which warrants final human review despite the added test coverage.

No open issues 🎉

What changed in this PR

This PR hardens the RustJava runtime so Java null contracts are enforced with proper Java exceptions instead of Rust panics, and reworks standard-stream initialization. Across java.lang, java.io, java.net, java.text, java.util, and org.rustjava classes, nullable references are now validated and converted into NullPointerException (or MalformedURLException) before any dereference. FileDescriptor.<clinit> now always publishes non-null in/out/err descriptors (leaving fd=0 when the host stream is unavailable, which surfaces as IOException on use), so System.<clinit> no longer needs to guard stdin. It also corrects Integer/Long.decode(null) to throw NullPointerException (not NumberFormatException), makes calendar/date-format setters tolerate null and fail safely on later use, and adds extensive regression tests.

Changes:

  • Add explicit null validation to runtime APIs (String, arraycopy, I/O streams, URL/handler/class-loader, ZIP/JAR, numeric decode) that previously risked panics.
  • Keep standard file descriptors non-null when host streams are missing and report IOException only on actual use; allow nullable calendar/number-format state with safe downstream failure.
  • Add integration tests covering rejected nulls, permitted empty operations, and recovery from nullable state.
File Description
io/​file_descriptor.rs Always creates non-null in/out/err descriptors (fd=0 when host stream unavailable).
lang/​system.rs Drops stdin null guard (now always non-null); adds arraycopy null check.
util/​calendar.rs, util/​gregorian_calendar.rs Nullable setTimeZone; identity/null-tz handling in equals; NPE in get/hashCode/compute on null tz.
text/​simple_date_format.rs Adds DateParseError enum and null-numberFormat NPE path; NPE on null calendar/timeZone/numberFormat.
text/​date_format.rs Setters accept null; get/set/isLenient/clone throw NPE when backing state is null.
lang/​string.rs Null checks for byte/char/String/StringBuffer constructors, concat, getChars.
lang/​integer.rs, lang/​long.rs decode(null) now throws NullPointerException.
lang/​class_loader.rs, lang/​throwable.rs Null checks for loadClass/getResource and printStackTrace.
net/​url.rs, net/​url_stream_handler.rs, net/​url_class_loader.rs, net/​jar_url_connection.rs Reject null spec/url/array/name with appropriate exceptions.
io/​filter_input_stream.rs, io/​filter_output_stream.rs, io/​data_input_stream.rs, io/​data_output_stream.rs Guard null underlying stream and null/empty arguments; preserve valid empty ops.
io/​file.rs, io/​file_input_stream.rs, io/​file_output_stream.rs, io/​random_access_file.rs, io/​reader.rs, io/​writer.rs, io/​input_stream_reader.rs, io/​output_stream_writer.rs, io/​buffered_output_stream.rs Null checks on constructor/read/write arguments.
util/​zip/​zip_file.rs, util/​zip/​zip_entry.rs, org/​rustjava/​lang/​rust_jar_class_loader.rs, org/​rustjava/​net/​file_url_handler.rs, org/​rustjava/​net/​url_path.rs Reject null file/entry/name/url/path.
tests/​classes/​** (io, lang, net, text, util, org) New regression tests for null rejection, empty-op acceptance, and recovery.

Review effort: Balanced

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