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

CompactNumberFormat integer parsing fails when string has no suffix

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • 17, 21, 23, 24
    • core-libs
    • b01
    • generic
    • generic
    • Verified

      See the following snippet, which demonstrates unexpected behavior

      var fmt = NumberFormat.getCompactNumberInstance(Locale.US, NumberFormat.Style.SHORT)
      fmt.parse("5") // returns 5
      fmt.parse("5K") // returns 5000
      fmt.setParseIntegerOnly(true)
      fmt.parse("5K") // returns 5000
      fmt.parse("5") // unexpectedly throws StringIndexOutOfBoundsException

      The position in parse needs to be checked before invoking charAt.

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

              Created:
              Updated:
              Resolved: