RFR: 8068958: Timestamp.from(Instant) should throw when conversion is not possible

Eamonn McManus emcmanus at openjdk.org
Thu Dec 21 23:22:46 UTC 2023


On Thu, 21 Dec 2023 21:51:10 GMT, Eamonn McManus <emcmanus at openjdk.org> wrote:

> Multiplying with `*` never produces `ArithmeticException`, so the catch in the existing code is never triggered. `Math.multiplyExact` does produce `ArithmeticException` if the multiplication overflows. So we can use that, and rethrow `IllegalArgumentException` as the specification says.
> 
> There is a small compatibility risk, in that code may have been relying on the previous silent overflow, and will now get an exception. But an exception is surely better than the nonsense results that overflow produces.
> 
> Thanks to Kurt Kluever for the test cases.

I think the three overflow cases we have are probably enough? (Just too big, as big as possible, as small as possible.)

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17181#discussion_r1434585279


More information about the core-libs-dev mailing list