Skip to content

[rustjava-runtime-time-todo-impl] fix: implement time APIs in RuntimeImpl + regression fixture - #2

Merged
Jun025 merged 3 commits into
mainfrom
runtime-time-impl
Jul 22, 2026
Merged

[rustjava-runtime-time-todo-impl] fix: implement time APIs in RuntimeImpl + regression fixture#2
Jun025 merged 3 commits into
mainfrom
runtime-time-impl

Conversation

@Jun025

@Jun025 Jun025 commented Jul 22, 2026

Copy link
Copy Markdown
Owner

What

The only production Runtime implementation (RuntimeImpl, the sole path used by the rust_java binary via src/lib.rs) had now(), sleep(), and r#yield() left as todo!(). Any Java program touching System.currentTimeMillis(), Thread.sleep(), Thread.yield(), new Date(), Timer, or Object.wait(long) died with a Rust panic instead of running. CI stayed green because the test_data corpus used none of these APIs and TestRuntime had its own implementations.

Changes

  • src/runtime.rs: now() → epoch ms via SystemTime; sleep()tokio::time::sleep; r#yield()tokio::task::yield_now
  • test_utils/src/lib.rs: fill the matching r#yield() todo!() so test/binary behavior stays identical
  • Cargo.toml: add tokio time feature to both target sections (only change; no other features/versions touched)
  • test_data/TimeApi.{class,txt}: new fixture (compiled --release 21) exercising currentTimeMillis / yield / sleep / Date through the RuntimeImpl integration path, with deterministic assertions only (positivity, monotonicity, ≥50ms elapsed after a 100ms sleep — no absolute-time or tight-timing checks)

Fixture source (repo convention keeps only .class + .txt):

import java.util.Date;

public class TimeApi {
    public static void main(String[] args) throws InterruptedException {
        long start = System.currentTimeMillis();
        System.out.println(start > 0 ? "currentTimeMillis positive" : "FAIL currentTimeMillis");
        Thread.yield();
        System.out.println("yield returned");
        Thread.sleep(100);
        long end = System.currentTimeMillis();
        System.out.println(end >= start ? "monotonic after sleep" : "FAIL monotonic");
        System.out.println(end - start >= 50 ? "sleep elapsed" : "FAIL sleep elapsed");
        Date date = new Date();
        System.out.println(date.getTime() > 0 ? "date positive" : "FAIL date");
    }
}

Evidence

Before fix (fixture added first — reproduces through RuntimeImpl):

thread 'test_class' panicked at src/runtime.rs:110:9:
not yet implemented

After fix:

  • cargo test --all: all green, 0 failures (test_class now includes TimeApi: 1 passed)
  • Deployed binary: cd test_data && rust_java TimeApi → all 5 assertion lines pass, exit 0
  • cargo build, cargo fmt --check, cargo clippy --all-targets clean

Non-goals (per ticket)

  • jvm_rust/src/interpreter.rs:629 remaining todo!()
  • Timer/scheduling semantics beyond panic removal
  • No upstream (dlunch/RustJava) contact

🤖 Generated with Claude Code

jun0 and others added 2 commits July 22, 2026 18:14
System.currentTimeMillis(), Thread.sleep(), Thread.yield(), new Date()
and everything else routed through Runtime::now/sleep/yield crashed the
deployed binary with a Rust panic because the only production Runtime
implementation left them as todo!(). Tests stayed green because the
integration corpus never exercised these APIs and TestRuntime had its
own (partial) implementations.

- RuntimeImpl::now -> SystemTime since UNIX_EPOCH in ms
- RuntimeImpl::sleep -> tokio::time::sleep
- RuntimeImpl::yield -> tokio::task::yield_now (also fills the todo!()
  in TestRuntime so test and binary behavior match)
- root Cargo.toml: add tokio "time" feature (both target sections)
- test_data/TimeApi: fixture calling currentTimeMillis/yield/sleep/Date
  with deterministic assertions (positivity/monotonicity/min-elapsed),
  locking the regression through the RuntimeImpl integration path

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Resolve STATE.md/REPORT.md add/add conflicts with the superset per the
strategy recorded in STATE.md. No code changes vs approved pin 3afb6cc.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Jun025
Jun025 merged commit 13ab950 into main Jul 22, 2026
7 of 8 checks passed
@Jun025
Jun025 deleted the runtime-time-impl branch July 22, 2026 22:21
Jun025 pushed a commit that referenced this pull request Jul 22, 2026
STATE.md superset resolution; REPORT.md auto-merged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant