RFR: 8068958: Timestamp.from(Instant) should throw when conversion is not possible
Eamonn McManus
emcmanus at openjdk.org
Thu Dec 21 21:57:02 UTC 2023
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.
-------------
Commit messages:
- 8068958: Timestamp.from(Instant) should throw when conversion is not possible
Changes: https://git.openjdk.org/jdk/pull/17181/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=17181&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8068958
Stats: 30 lines in 2 files changed: 29 ins; 0 del; 1 mod
Patch: https://git.openjdk.org/jdk/pull/17181.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/17181/head:pull/17181
PR: https://git.openjdk.org/jdk/pull/17181
More information about the core-libs-dev
mailing list