RFR: 8264161: BigDecimal#stripTrailingZeros can throw undocumented ArithmeticException
Joe Darcy
joe.darcy at oracle.com
Wed Apr 21 16:25:39 UTC 2021
On 4/21/2021 9:14 AM, Fabian Meumertzheim wrote:
> On Thu, 25 Mar 2021 08:19:24 GMT, Fabian Meumertzheim <github.com+4312191+fmeum at openjdk.org> wrote:
>
>> Adds missing @throws declarations for ArithmeticException to the public
>> function
>> java.math.BigDecimal#stripTrailingZeros
>> as well as the private helper functions
>> java.math.BigDecimal#createAndStripZerosToMatchScale(long, int, long)
>> java.math.BigDecimal#createAndStripZerosToMatchScale(BigInteger, int, long)
>>
>> stripTrailingZeros calls one of the two helper functions, both of which
>> can repeatedly decrease the scale by 1 until it underflows. If it does,
>> the call to checkScale will result in an ArithmeticException (overflow).
>> Please note the issue [8264161](https://bugs.openjdk.java.net/browse/JDK-8264161) has already been addressed by:
>> #3204
> @RogerRiggs The fix in #3204 remains incomplete as it does not update the `@throws` declarations. I could open a new bug for that, but unfortunately the form at https://bugreport.java.com/bugreport/start_form.do appears to be down: There is no server response when clicking "Submit", the request to https://bugreport.java.com/bugreport/submit_start.do just hangs forever.
Just was we don't think it is helpful to put an explicit
@throws NullPointerException if a argument is null
on every method that throws a NPE for a null argument, I don't think it
is helpful or necessary to explicitly note in every BigDecimal method
with rounding that it could throw ArithmeticException. The general
class-level statement
* <p>As a 32-bit integer, the set of values for the scale is large,
* but bounded. If the scale of a result would exceed the range of a
* 32-bit integer, either by overflow or underflow, the operation may
* throw an {@code ArithmeticException}.
in meant to capture the needed information.
-Joe
More information about the core-libs-dev
mailing list