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

DecimalFormat not throwing any exception for invalid pattern

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • None
    • core-libs
    • None

      A DESCRIPTION OF THE PROBLEM :

      As per the API specification of DecimalFormat "A DecimalFormat pattern contains a positive and negative subpattern, for example, "#,##0.00;(#,##0.00)". Each subpattern has a prefix, numeric part, and suffix.", but it does not throw any exception when an invalid pattern is used, such as "(#(#)" (numeric part / special character after suffix). Below are some examples of similar invalid patterns and the output given by DecimalFormat

      1. formatting -3456.349347 with pattern (#(#) (invalid positive sub-pattern) returns -(3456()
      2. formatting -3456.349347 with pattern #,##0.0#;(#(#) (invalid negative sub-pattern) returns (3,456.35()

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :

      Execute below code snippet
      =======================================
      DecimalFormat format = new DecimalFormat("(#(#)");
      double number = -3456.349347;
      System.out.println(format.format(number));
      =======================================

      Expected
      Throw Exception

      Actual
      Returns unpredictable results
      -(3456() for (#(#) and (3,456.35() for #,##0.0#;(#(#)

      REPRODUCIBILITY :
      This bug can be reproduced always.

            nishjain Nishit Jain
            nishjain Nishit Jain
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: