RFR: 8318915: Enhance checks in BigDecimal.toPlainString() [v2]

Brian Burkhalter bpb at openjdk.org
Wed Nov 8 17:51:01 UTC 2023


On Wed, 8 Nov 2023 09:55:13 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:

>> src/java.base/share/classes/java/math/BigDecimal.java line 3510:
>> 
>>> 3508:                 : intVal.toString();
>>> 3509:             int len = str.length() + trailingZeros;
>>> 3510:             if (len < 0) {
>> 
>> One could use `Math.addExact`, which has an intrinsic, and convert any thrown `ArithmeticException` into an OOME but I am not sure it's worth it.
>
> Yes, I considered that but I'm not sure how the throwing and catching of `ArithmeticException` with `*Exact` intrinsics is optimized by C2, so I have a manual overflow check for the addition.

I think it's fine as is.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16457#discussion_r1386998599


More information about the core-libs-dev mailing list