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

Instant.ofEpochMilli says it can throw an exception that it can't

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 21
    • core-libs
    • None
    • source, behavioral
    • minimal
    • No risk since we are just removing a false claim about possible exceptions.
    • Java API
    • SE

      Summary

      Instant.ofEpochMilli says it can throw DateTimeException, but it cannot.

      Problem

      Instant.ofEpochMilli says it can throw DateTimeException, but it cannot. This means that conscientious developers may waste time trying to handle an exception that can never happen. The argument to this method is the same sort of long as System.currentTimeMillis() so it would actually be quite surprising if some values were not accepted.

      Solution

      Remove the offending @throws clause.

      Specification

      diff --git a/src/java.base/share/classes/java/time/Instant.java b/src/java.base/share/classes/java/time/Instant.java
      index 5c27879b6d1b..810581c42332 100644
      --- a/src/java.base/share/classes/java/time/Instant.java
      +++ b/src/java.base/share/classes/java/time/Instant.java
      @@ -342,7 +342,6 @@ public static Instant ofEpochSecond(long epochSecond, long nanoAdjustment) {
            *
            * @param epochMilli  the number of milliseconds from 1970-01-01T00:00:00Z
            * @return an instant, not null
      -     * @throws DateTimeException if the instant exceeds the maximum or minimum instant
            */
           public static Instant ofEpochMilli(long epochMilli) {
               long secs = Math.floorDiv(epochMilli, 1000);

            emcmanus Eamonn McManus
            emcmanus Eamonn McManus
            Daniel Fuchs, Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: