Summary
The grouping size
of DecimalFormat
should not accept negative values.
Problem
grouping size
is defined as:
The grouping size is a constant number of digits between the grouping characters, such as 3 for 100,000,000 or 4 for 1,0000,0000.
So it should not take a negative value. Also as it is cast to byte
type, the size should not be greater than Byte.MAX_VALUE
.
Solution
If an invalid value is specified in DecimalFormat.setGroupingSize(int)
, throw an IllegalArgumentException
.
Specification
Add the following sentence in the last paragraph of the method description.
* Invalid value, i.e., negative or greater than
* {@link java.lang.Byte#MAX_VALUE Byte.MAX_VALUE}, will throw an
* {@code IllegalArgumentException}.
Add the following @throws
sentence at the last of the method description.
* @throws IllegalArgumentException if {@code newValue} is negative or
* greater than {@link java.lang.Byte#MAX_VALUE Byte.MAX_VALUE}
- csr of
-
JDK-8212749 DecimalFormat.setGroupingSize(int) allows setting negative grouping size
-
- Closed
-
- relates to
-
JDK-8231984 Clarify semantics of DecimalFormat.getGroupingSize(0)
-
- Resolved
-