RFR: 8368856: Add a method that performs saturating addition of a Duration to an Instant [v10]

Pavel Rappo prappo at openjdk.org
Tue Oct 21 08:14:05 UTC 2025


> We recently [discussed] the possibility of introducing saturating arithmetic for deadline computation. Consider this PR as a starting point. Once we agree on the implementation, I'll file a CSR.
> 
> I created a method in `Instant` to add `Duration`. One could argue that the proper way would be to go all the way and create a method in `Temporal` to add `TemporalAmount`. Or maybe even expand the functionality, and create an additional method in `Temporal` to subtract `TemporalAmount`.
> 
> My current thinking is that if we were to do that, there would be a lot of expensive, unused code. Saturating logic seems to be only useful for `Instant` and `Duration`.
> 
> Even if we decide to extend `Temporal` to add/subtract `TemporalAmount`, it could always be done later. From the perspective of `Instant`, `plus(TemporalAmount)` will be just an overload of `plus(Duration)`.
> 
> [discussed]: https://mail.openjdk.org/pipermail/core-libs-dev/2025-September/151098.html

Pavel Rappo has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 14 additional commits since the last revision:

 - Merge remote-tracking branch 'jdk/master' into 8368856
 - Address feedback and fine tune the spec
   
   Good catch, Naoto! Double checked by make docs-jdk-api.
 - Simplify impl
 - Clarify spec
 - Revert "Add Instant.minusSaturating(Duration)"
   
   This reverts commit 35537856f1759c7abbe2b5c5bbb267a90612f729.
 - Add test for null
 - Fix copy-paste typos
 - Add Instant.minusSaturating(Duration)
 - Slightly improve corner case
 - Strengthen the test
 - ... and 4 more: https://git.openjdk.org/jdk/compare/a14b1d2c...393d3298

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/27549/files
  - new: https://git.openjdk.org/jdk/pull/27549/files/3b964ce8..393d3298

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=27549&range=09
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=27549&range=08-09

  Stats: 45765 lines in 1294 files changed: 27121 ins; 11981 del; 6663 mod
  Patch: https://git.openjdk.org/jdk/pull/27549.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/27549/head:pull/27549

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


More information about the core-libs-dev mailing list