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

Alan Bateman alanb at openjdk.org
Fri Mar 10 07:53:04 UTC 2023


On Thu, 9 Mar 2023 22:07:17 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

> 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.

I'm surprised it hasn't come up as declaring that it throws DateTimeException "if the instant exceeds the maximum or minimum instant" is a testable assertion. Maybe as part of this removal there should be an apiNote will some verbiage on what can be represented.

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

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


More information about the core-libs-dev mailing list