-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
11
-
generic
-
windows
ADDITIONAL SYSTEM INFORMATION :
On Windows. (MacOS, Linux worked fine as far as I remember)
Fails with Java 8 and Java 11, 12, other versions where not tested.
A DESCRIPTION OF THE PROBLEM :
Since we are using the locale provider "HOST" (setting the system property "java.locale.providers"), the method java.text.SimpleDateFormat#parse fails to parse strings (representing valid dates) if the decimal separator and the date separator are equal.
For example decimal separator is "." and dates are in format "dd.MM.yyyy".
Without adding "java.locale.providers" it works fine, also if the separators differ (e.g. date format is "dd/MM/yyyy" and decimal separator is"."). And it seems to happen only on Windows.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Set the decimal separator to "." on your Windows 10 machine (or the complete locale to something like English(USA)).
Run the attached source code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
"Successfully parsed '01.05.2019' to java.util.Date() with SimpleDateFormat#parse (Wed May 01 00:00:00 CEST 2019)"
ACTUAL -
"Could not parse string '01.05.2019' to java.util.Date() with SimpleDateFormat#parse"
java.text.ParseException: Unparseable date: "01.05.2019"
at java.base/java.text.DateFormat.parse(DateFormat.java:395)
at de.m.SdfParsingBug.main(SdfParsingBug.java:14)
---------- BEGIN SOURCE ----------
package de.m;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class SdfParsingBug {
public static void main(String[] args) {
System.setProperty("java.locale.providers", "HOST,COMPAT,SPI");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
String dateAsString = "01.05.2019";
try {
Date parsedToDate = dateFormat.parse(dateAsString);
System.out.println("Successfully parsed '" + dateAsString + "' to java.util.Date() with SimpleDateFormat#parse (" + parsedToDate + ")");
} catch (ParseException e) {
System.out.println("Could not parse string '" + dateAsString + "' to java.util.Date() with SimpleDateFormat#parse");
e.printStackTrace();
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Parsing with java.time.LocalDate#parse works fine. Still in some cases it is not possible to change the code to use LocalDate#parse, instead of SimpleDateFormat#parse.
FREQUENCY : always
On Windows. (MacOS, Linux worked fine as far as I remember)
Fails with Java 8 and Java 11, 12, other versions where not tested.
A DESCRIPTION OF THE PROBLEM :
Since we are using the locale provider "HOST" (setting the system property "java.locale.providers"), the method java.text.SimpleDateFormat#parse fails to parse strings (representing valid dates) if the decimal separator and the date separator are equal.
For example decimal separator is "." and dates are in format "dd.MM.yyyy".
Without adding "java.locale.providers" it works fine, also if the separators differ (e.g. date format is "dd/MM/yyyy" and decimal separator is"."). And it seems to happen only on Windows.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Set the decimal separator to "." on your Windows 10 machine (or the complete locale to something like English(USA)).
Run the attached source code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
"Successfully parsed '01.05.2019' to java.util.Date() with SimpleDateFormat#parse (Wed May 01 00:00:00 CEST 2019)"
ACTUAL -
"Could not parse string '01.05.2019' to java.util.Date() with SimpleDateFormat#parse"
java.text.ParseException: Unparseable date: "01.05.2019"
at java.base/java.text.DateFormat.parse(DateFormat.java:395)
at de.m.SdfParsingBug.main(SdfParsingBug.java:14)
---------- BEGIN SOURCE ----------
package de.m;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class SdfParsingBug {
public static void main(String[] args) {
System.setProperty("java.locale.providers", "HOST,COMPAT,SPI");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
String dateAsString = "01.05.2019";
try {
Date parsedToDate = dateFormat.parse(dateAsString);
System.out.println("Successfully parsed '" + dateAsString + "' to java.util.Date() with SimpleDateFormat#parse (" + parsedToDate + ")");
} catch (ParseException e) {
System.out.println("Could not parse string '" + dateAsString + "' to java.util.Date() with SimpleDateFormat#parse");
e.printStackTrace();
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Parsing with java.time.LocalDate#parse works fine. Still in some cases it is not possible to change the code to use LocalDate#parse, instead of SimpleDateFormat#parse.
FREQUENCY : always
- relates to
-
JDK-8232860 Error formatting integer values with MessageFormat.format() using HOST provider
- Resolved