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

[Fmt-Nu] DecimalFormat.applyPattern() allows suffix with special characters

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6
    • core-libs
    • None
    • sparc
    • solaris_9

      The specification of DecimalFormat states:

       Prefix:
               any Unicode characters except \uFFFE, \uFFFF, and special characters
       Suffix:
               any Unicode characters except \uFFFE, \uFFFF, and special characters

      However, the implementation allows suffix with special characters like "#".

      For example:

      import java.text.*;

      public class DecimalFormatTest01 {

          public static void main (String[] args) {
              String pattern1 = "###,000.000suffix2##";
              DecimalFormat df = new DecimalFormat();
              try {
                  df.applyPattern(pattern1);
                  System.out.println("FAILED: IllegalArgumentException expected for pattern " + pattern1);
                  System.out.println("Suffix: " + df.getPositiveSuffix());
              } catch (IllegalArgumentException iae) {
                  // OKAY
              }
          }
      }

      Output in JDK 6.0:

      FAILED: IllegalArgumentException expected for pattern ###,000.000suffix2##
      Suffix: suffix2

            nishjain Nishit Jain
            xwangsunw Xiaozhong Wang (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: