Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8310232

java.time.Clock$TickClock.millis() fails in runtime when tick is 1 microsecond

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 22
    • 17.0.7, 21, 22
    • core-libs
    • b05
    • x86_64
    • os_x
    • Verified

    Description

      A DESCRIPTION OF THE PROBLEM :
      When `TickClock` is created with a tick that is less than a millisecond its `millis()` method throws ArithmeticException division by zero.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. create a microsecond precision clock:
      Clock microsecondPrecisionClock = Clock.tick(Clock.systemUTC(), Duration.ofNanos(1000));

      2. Call millis() method throw runtime exception
      microsecondPrecisionClock.millis(); // java.lang.ArithmeticException: / by zero

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Get current millisecond instant of the clock without throwing an error
      ACTUAL -
      java.lang.ArithmeticException: / by zero

      ---------- BEGIN SOURCE ----------
      public class TickClockTest {
          public static void main(String[] args) {
              Clock microsecondPrecisionClock = Clock.tick(Clock.systemUTC(), Duration.ofNanos(1000));
              microsecondPrecisionClock.millis();
          }
      }
      ---------- END SOURCE ----------

      Attachments

        Issue Links

          Activity

            People

              naoto Naoto Sato
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: