DecimalFormat.setGroupingSize(int) allows setting negative grouping size

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 14
    • Affects Version/s: None
    • Component/s: core-libs
    • b19
    • Verified

      The DecimalFormat.setGroupingSize(int) allows setting negative values, which may not be correct for a property like grouping size.

      DecimalFormat fmt = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US);
      fmt.setGroupingSize(-2);
      System.out.println(fmt.getGroupingSize());

      Instead of throwing exception, the above code snippet accepts -2 to be set for grouping size

      Expected: Throw an IllegalArgumentException
      Actual: Negative values are accepted.

      Also, the specification of setGroupingSize() says that "The value passed in is converted to a byte, which may lose information."

      so, setting a value outside "byte" boundary, wraps around e.g.
      fmt.setGroupingSize(255); // makes the grouping size as -1

      Instead of accepting all integer values, a range check should be applied before setting the grouping size field. e.g. values between 0-127

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

              Created:
              Updated:
              Resolved: