RFR: 8310232: java.time.Clock$TickClock.millis() fails in runtime when tick is 1 microsecond [v2]

Aleksey Shipilev shade at openjdk.org
Wed Jun 28 10:15:12 UTC 2023


On Tue, 27 Jun 2023 16:34:40 GMT, Naoto Sato <naoto at openjdk.org> wrote:

>> Fixing the `/ by zero` exception with tick durations less than a millisecond.
>
> Naoto Sato 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 four additional commits since the last revision:
> 
>  - Merge branch 'master' into JDK-8310232-TickClock-ArithExp
>  - Removed bugid from the test class description
>  - refactor return statement
>  - 8310232: java.time.Clock$TickClock.millis() fails in runtime when tick is 1 microsecond

src/java.base/share/classes/java/time/Clock.java line 762:

> 760:         public long millis() {
> 761:             long millis = baseClock.millis();
> 762:             return tickNanos < 1000_000L ? millis : millis - Math.floorMod(millis, tickNanos / 1000_000L);

Cleaner precedence:

Suggestion:

            long trunc = (tickNanos >= 1000_000L) ? Math.floorMod(millis, tickNanos / 1000_000L) : 0;
            return millis - trunc;

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

PR Review Comment: https://git.openjdk.org/jdk/pull/14657#discussion_r1244999939


More information about the core-libs-dev mailing list