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.
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.
- duplicates
-
JDK-4503190 [Fmt-Nu] Method java.text.DecimalFormat.applyPattern(String pattern) works incorrectly.
- Closed
- relates to
-
JDK-6609740 [Fmt-De] format error in DecimalFormat
- Resolved