DecimalFormat.setGroupingSize(int) allows setting negative grouping size

XMLWordPrintable

    • Type: CSR
    • Resolution: Approved
    • Priority: P4
    • 14
    • Component/s: core-libs
    • None
    • behavioral
    • low
    • An exception is thrown for those invalid input values.
    • Java API
    • JDK

      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}
      

            Assignee:
            Naoto Sato
            Reporter:
            Nishit Jain
            Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: