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

DecimalFormat and CompactNumberFormat do allow U+FFFE and U+FFFF in the pattern

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 22
    • core-libs
    • None
    • behavioral
    • minimal
    • A specification only update to reflect actual behavior.
    • Java API
    • SE

      Summary

      Correct the prefix and suffix portion of pattern syntax for Decimal / CompactNumber Format.

      Problem

      Both of the Format classes list the suffix and prefix as allowing: "any Unicode characters except U+FFFE, U+FFFF, and special characters".

      However, U+FFFE and U+FFFF are both able to be included in the pattern syntax with no exception thrown.

      E.g. (For clarification, in the example, the U+FFFE and U+FFFF characters are replaced by U+FFFD / replacement character)

      String uFFFE = "\uFFFE";
      String uFFFF = "\uFFFF";
      var a = new DecimalFormat("prefixStart"+uFFFE+"0.00"+uFFFF+"SuffixEnd");
      a.format(1); // returns "prefixStart�1.00�SuffixEnd"

      Solution

      Remove U+FFFE and U+FFFF from both the prefix and suffix definition. Also remove 'Unicode', as a Java character is composed of Unicode codepoints.

      Specification

      CompactNumberFormat.java

        * <i>Prefix:</i>
      - *      Any Unicode characters except {@code U+FFFE}, {@code U+FFFF}, and
      - *      {@linkplain DecimalFormat##special_pattern_character special characters}.
      + *      Any characters except the {@linkplain
      + *      DecimalFormat##special_pattern_character special pattern characters}
        * <i>Suffix:</i>
      - *      Any Unicode characters except {@code U+FFFE}, {@code U+FFFF}, and
      - *      {@linkplain DecimalFormat##special_pattern_character special characters}.
      + *      Any characters except the {@linkplain
      + *      DecimalFormat##special_pattern_character special pattern characters}

      DecimalFormat.java

        * <i>Prefix:</i>
      - *         any Unicode characters except {@code U+FFFE}, {@code U+FFFF}, and special characters
      + *         Any characters except the {@linkplain ##special_pattern_character
      + *         special pattern characters}
        * <i>Suffix:</i>
      - *         any Unicode characters except {@code U+FFFE}, {@code U+FFFF}, and special characters
      + *         Any characters except the {@linkplain ##special_pattern_character
      + *         special pattern characters}
        * <i>Number:</i>
        *         <i>Integer</i> <i>Exponent<sub>opt</sub></i>
        *         <i>Integer</i> . <i>Fraction</i> <i>Exponent<sub>opt</sub></i>

            jlu Justin Lu
            jlu Justin Lu
            Naoto Sato
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: