JDK-8044849 : DecimalFormat looses closing parenthesis when using (#) as negative subpattern
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 7u25
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2014-06-03
  • Updated: 2017-01-13
  • Resolved: 2017-01-13
Related Reports
Duplicate :  
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_25"

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
Hello,

The following test case does not produce the same output twice contrarily to what the DecimalFormat javadoc says:

import java.text.DecimalFormat;

public class Test {

    public static void main(String[] args) throws Exception {
        String pattern1 = "#,##0.0#;(#)";
        String pattern2 = "#,##0.0#;(#,##0.0#)";
        DecimalFormat format1 = new DecimalFormat(pattern1);
        System.out.println(pattern1 + " -> " + format1.format(-1000));
        DecimalFormat format2 = new DecimalFormat(pattern2);
        System.out.println(pattern2 + " -> " + format2.format(-1000));
    }

}

Ouput is:

#,##0.0#;(#) -> (1,000.0
#,##0.0#;(#,##0.0#) -> (1,000.0)

Notice the missing closing parenthesis.

Best regards,

Thomas Leplus

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the following piece of code:

import java.text.DecimalFormat;

public class Test {

    public static void main(String[] args) throws Exception {
        String pattern1 = "#,##0.0#;(#)";
        String pattern2 = "#,##0.0#;(#,##0.0#)";
        DecimalFormat format1 = new DecimalFormat(pattern1);
        System.out.println(pattern1 + " -> " + format1.format(-1000));
        DecimalFormat format2 = new DecimalFormat(pattern2);
        System.out.println(pattern2 + " -> " + format2.format(-1000));
    }

}

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
#,##0.0#;(#) -> (1,000.0)
#,##0.0#;(#,##0.0#) -> (1,000.0)
ACTUAL -
#,##0.0#;(#) -> (1,000.0
#,##0.0#;(#,##0.0#) -> (1,000.0)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.text.DecimalFormat;

public class Test {

    public static void main(String[] args) throws Exception {
        String pattern1 = "#,##0.0#;(#)";
        String pattern2 = "#,##0.0#;(#,##0.0#)";
        DecimalFormat format1 = new DecimalFormat(pattern1);
        System.out.println(pattern1 + " -> " + format1.format(-1000));
        DecimalFormat format2 = new DecimalFormat(pattern2);
        System.out.println(pattern2 + " -> " + format2.format(-1000));
    }

}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use the full pattern instead of (#).


Comments
Closing it as duplicate of JDK-6609740
13-01-2017