Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2134882 | 5.0u8 | Joe Darcy | P4 | Resolved | Fixed | b01 |
OPERATING SYSTEM(S)
Windows XP
FULL JDK VERSION(S):
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode)
DESCRIPTION:
In some cases, rounding can cause an unnoticed overflow of a BigDecimal's scale.
This is caused by an unchecked manipulation of the scale in BigDecimal.dropDigits:
- Minimal source code that demonstrates the problem
import java.math.*;
public class BDScaleOverFlow {
public static void main(String[] args) {
BigDecimal j = BigDecimal.valueOf(11, Integer.MIN_VALUE);
System.out.format("%s (scale: %s)\n", j, j.scale());
//The following should throw an exception since we would be
//forcing the scale to fall below Integer.MIN_VALUE
System.out.println("About to round to precision 1, expecting exception.");
j = j.round(new MathContext(1));
System.out.format("%s (scale: %s)", j, j.scale());
}
}
- Exact text of any error messages
Output:
1.1E+2147483649 (scale: -2147483648)
About to round to precision 1, expecting exception.
1E-2147483647 (scale: 2147483647)
The testcase should throw an exception.
Windows XP
FULL JDK VERSION(S):
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode)
DESCRIPTION:
In some cases, rounding can cause an unnoticed overflow of a BigDecimal's scale.
This is caused by an unchecked manipulation of the scale in BigDecimal.dropDigits:
- Minimal source code that demonstrates the problem
import java.math.*;
public class BDScaleOverFlow {
public static void main(String[] args) {
BigDecimal j = BigDecimal.valueOf(11, Integer.MIN_VALUE);
System.out.format("%s (scale: %s)\n", j, j.scale());
//The following should throw an exception since we would be
//forcing the scale to fall below Integer.MIN_VALUE
System.out.println("About to round to precision 1, expecting exception.");
j = j.round(new MathContext(1));
System.out.format("%s (scale: %s)", j, j.scale());
}
}
- Exact text of any error messages
Output:
1.1E+2147483649 (scale: -2147483648)
About to round to precision 1, expecting exception.
1E-2147483647 (scale: 2147483647)
The testcase should throw an exception.
- backported by
-
JDK-2134882 Unchecked scale manipulation in BigDecimal.dropDigits
-
- Resolved
-