Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8333755

NumberFormat integer only parsing breaks when format has suffix

XMLWordPrintable

    • b04
    • generic
    • generic
    • Verified

      The JDK defines two concrete subclasses of NumberFormat, DecimalFormat and CompactNumberFormat.

      Unlike CompactNumberFormat, DecimalFormat fails parsing in integer only mode if the expected format contains a suffix and the parse string contains a decimal symbol. The implementation does not fully traverse the parse string upon encountering a decimal symbol. Thus the parse will always fail, since the suffix can not be matched.

      Instead of stopped the traversal during a decimal symbol encounter, we should continue, but stop appending digits to the digitList.

      A common example of this bug would be a percent instance parsing a string value that has a fractional portion.

      Adding on to this, further clarification should be added to make clear that while parsing in integer only mode, the ParsePosition index under DecimalFormat reflects the decimal symbol, but is not the case for CompactNumberFormat. In that case, the index is still reflected by the end of the parse string. Such differences can not be remedied due to compatibility concerns.

            jlu Justin Lu
            jlu Justin Lu
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: