On Thu, 9 Mar 2023 19:49:29 GMT, Eamonn McManus <emcma...@openjdk.org> wrote:

> Instant.ofEpochMilli says this:
> 
> 
> @throws DateTimeException if the instant exceeds the maximum or minimum 
> instant
> 
> 
> But that can't happen. Even given `Long.MIN_VALUE` or `Long.MAX_VALUE` it 
> does not throw. That's already implicitly tested in 
> [`TestInstant`](https://github.com/openjdk/jdk/blob/a9dba565688a29bef8626488c47519008dcadbe8/test/jdk/java/time/test/java/time/TestInstant.java#L84),
>  which calls it with both those values.

I see your point, but no one has stumbled into/over it before.
Rationalizing here...
The presence of the exception is a reminder that there are values of epoch 
milliseconds that `Instant` can not represent.
It is also the case that `long` cannot represent them either.
For example  `Instant.MIN.toEpochMilli()` throws and the method 
`Instant.ofEpochSecond(sec, nanos)` throws with Long.MIN_VALUE and 
Long.MAX_VALUE.

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

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

Reply via email to