[classlib][math] BigDecimal.divide throws ArrayIndexOufOfBoundsException when called with too
large scale
---------------------------------------------------------------------------------------------------------
Key: HARMONY-6272
URL: https://issues.apache.org/jira/browse/HARMONY-6272
Project: Harmony
Issue Type: Bug
Components: Classlib
Environment: all
Reporter: Catherine Hope
BigDecimal.divide(BigDecimal, int, RoundingMode) throws an ArrayIndexOutOfBoundsException
when called with a scale that's too large, instead of the expected ArithmeticException.
testcase:
BigDecimal bd = (new BigDecimal("4")).divide(new BigDecimal("1"), Integer.MAX_VALUE, 1);
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: -2147483644
at java.math.Multiplication.multiplyByTenPow(Multiplication.java:409)
at java.math.BigDecimal.movePoint(BigDecimal.java:2062)
at java.math.BigDecimal.movePointLeft(BigDecimal.java:2043)
The exception is thrown from Multiplication.multiplyByTenPow which is being called with a
negative index, though it has a precondition that it should be 0 or above. This is occurring
since there's an unnecessary cast to int after a negation, which means if:
long l = -(Integer.MAX_VALUE + 1);
long negate = (int)-l;
then negate is still set to -(Integer.MAX_VALUE + 1) instead of (Integer.MAX_VALUE + 1)
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
|