Summary
The spec for BigDecimal(String)
requires the exponent to be in the int
range.
This causes the issue described in JDK-8233760, where a string produced by BigDecimal.toString()
cannot be parsed by the constructor.
Problem
The spec of BigDecimal(String)
limits the values of the exponent part to be in the int
range. This is unnecessarily restrictive.
For example, BigDecimal.valueOf(10, Integer.MIN_VALUE).toString()
produces "1.0E+2147483649"
, but new BigDecimal("1.0E+2147483649")
throws. This is unacceptable, as every string returned by toString()
and passed to the constructor must produce the same BigDecimal
.
The cause of the constructor throwing is the requirement for the exponent part to be in the int
range.
Solution
Drop the requirement for the exponent to lie in the int
range from the spec of the constructor.
Specification
--- a/src/java.base/share/classes/java/math/BigDecimal.java
+++ b/src/java.base/share/classes/java/math/BigDecimal.java
@@ -819,9 +798,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
*
* <p>The exponent consists of the character {@code 'e'}
* (<code>'\u0065'</code>) or {@code 'E'} (<code>'\u0045'</code>)
- * followed by one or more decimal digits. The value of the
- * exponent must lie between -{@link Integer#MAX_VALUE} ({@link
- * Integer#MIN_VALUE}+1) and {@link Integer#MAX_VALUE}, inclusive.
+ * followed by one or more decimal digits.
*
* <p>More formally, the strings this constructor accepts are
* described by the following grammar:
- csr of
-
JDK-8233760 Result of BigDecimal.toString throws overflow exception on new BigDecimal(str)
-
- Closed
-