FULL PRODUCT VERSION :
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
If grouping separator is used NumberFormat parses even wrong inputs.
Say we have grouping separator set to ',' and decimal separator to '. then the non-valid input '1,,,,,5.5' is fully parsed as 15.5 without any complains.
By further analysis the problematic part lies in DecimalFormat.subparse method, it says it requires a digit after the grouping separator but if none comes and we have backed up last non-digit character nothing happens and the cycle goes on.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
NumberFormat nf = NumberFormat.getNumberInstance(Locale.ENGLISH);
try {
System.out.println(nf.parse("1,,,,5.5"));
} catch (ParseException e) {
e.printStackTrace();
}
---------- END SOURCE ----------
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
If grouping separator is used NumberFormat parses even wrong inputs.
Say we have grouping separator set to ',' and decimal separator to '. then the non-valid input '1,,,,,5.5' is fully parsed as 15.5 without any complains.
By further analysis the problematic part lies in DecimalFormat.subparse method, it says it requires a digit after the grouping separator but if none comes and we have backed up last non-digit character nothing happens and the cycle goes on.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
NumberFormat nf = NumberFormat.getNumberInstance(Locale.ENGLISH);
try {
System.out.println(nf.parse("1,,,,5.5"));
} catch (ParseException e) {
e.printStackTrace();
}
---------- END SOURCE ----------
- relates to
-
JDK-8327640 Allow NumberFormat strict parsing
- Resolved