RFR: 8357539: TimeSource.now() is not monotonic

Daniel Jeliński djelinski at openjdk.org
Thu May 22 09:58:28 UTC 2025


We observed a case where the instants returned by `TimeSource.now()` were returned in non-monotonic order. The reason was that sometimes we were using a delay calculated with one `localSource` as an input to a different (updated on another thread) `localSource`. This was confirmed by putting `assert firstNanos + delay == nanos;` under `instant(long, long)`.

The fix ensures that we won't accidentally use the incorrect delay by removing the `instant(long, long)` overload, and calculating the delay in the method where it is used.

No new test; instrumenting this class for testing would likely double its size.

-------------

Commit messages:
 - Ensure that delay is used with the correct timesource

Changes: https://git.openjdk.org/jdk/pull/25390/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=25390&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8357539
  Stats: 10 lines in 1 file changed: 1 ins; 3 del; 6 mod
  Patch: https://git.openjdk.org/jdk/pull/25390.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/25390/head:pull/25390

PR: https://git.openjdk.org/jdk/pull/25390


More information about the net-dev mailing list