JDK-8287376 : BigDecimal(String) must allow a larger range for the exponent
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.math
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 19
  • Submitted: 2022-05-26
  • Updated: 2022-06-04
  • Resolved: 2022-06-04
Related Reports
CSR :  
Description
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>'&#92;u0065'</code>) or {@code 'E'} (<code>'&#92;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:
```


Comments
Moving to Approved.
04-06-2022

Moving to Provisional.
02-06-2022