-
Bug
-
Resolution: Fixed
-
P3
-
11, 14, 15
ADDITIONAL SYSTEM INFORMATION :
Windows 10, "Country or region" set to "Germany", "Regional format" set to "English (United States)", but customized to use 24-hour time and use yyyy-mm-dd date format.
A DESCRIPTION OF THE PROBLEM :
Setting the java.locale.providers property to HOST and using DateTimeFormatter#ofLocalizedDate yields an exception when the format method of this formatter is called. This seems to be because the date-only pattern includes the time pattern as well.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the provided source code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Properly formatted date.
ACTUAL -
Exception in thread "main" java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: HourOfDay
at java.base/java.time.LocalDate.get0(LocalDate.java:709)
at java.base/java.time.LocalDate.getLong(LocalDate.java:688)
at java.base/java.time.format.DateTimePrintContext.getValue(DateTimePrintContext.java:308)
at java.base/java.time.format.DateTimeFormatterBuilder$NumberPrinterParser.format(DateTimeFormatterBuilder.java:2704)
at java.base/java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(DateTimeFormatterBuilder.java:2343)
at java.base/java.time.format.DateTimeFormatterBuilder$LocalizedPrinterParser.format(DateTimeFormatterBuilder.java:4762)
at java.base/java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(DateTimeFormatterBuilder.java:2343)
at java.base/java.time.format.DateTimeFormatter.formatTo(DateTimeFormatter.java:1847)
at java.base/java.time.format.DateTimeFormatter.format(DateTimeFormatter.java:1821)
at Scratch.main(scratch.java:10)
---------- BEGIN SOURCE ----------
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
class Scratch {
public static void main(String[] args) {
System.setProperty("java.locale.providers", "HOST");
DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL);
// Yields a different exception when also using .withLocale(Locale.ENGLISH) but still fails.
formatter.format(LocalDate.of(2020, 1, 1));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The only workaround I can think of right now is not using the HOST locale provider.
FREQUENCY : always
Windows 10, "Country or region" set to "Germany", "Regional format" set to "English (United States)", but customized to use 24-hour time and use yyyy-mm-dd date format.
A DESCRIPTION OF THE PROBLEM :
Setting the java.locale.providers property to HOST and using DateTimeFormatter#ofLocalizedDate yields an exception when the format method of this formatter is called. This seems to be because the date-only pattern includes the time pattern as well.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the provided source code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Properly formatted date.
ACTUAL -
Exception in thread "main" java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: HourOfDay
at java.base/java.time.LocalDate.get0(LocalDate.java:709)
at java.base/java.time.LocalDate.getLong(LocalDate.java:688)
at java.base/java.time.format.DateTimePrintContext.getValue(DateTimePrintContext.java:308)
at java.base/java.time.format.DateTimeFormatterBuilder$NumberPrinterParser.format(DateTimeFormatterBuilder.java:2704)
at java.base/java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(DateTimeFormatterBuilder.java:2343)
at java.base/java.time.format.DateTimeFormatterBuilder$LocalizedPrinterParser.format(DateTimeFormatterBuilder.java:4762)
at java.base/java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(DateTimeFormatterBuilder.java:2343)
at java.base/java.time.format.DateTimeFormatter.formatTo(DateTimeFormatter.java:1847)
at java.base/java.time.format.DateTimeFormatter.format(DateTimeFormatter.java:1821)
at Scratch.main(scratch.java:10)
---------- BEGIN SOURCE ----------
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
class Scratch {
public static void main(String[] args) {
System.setProperty("java.locale.providers", "HOST");
DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL);
// Yields a different exception when also using .withLocale(Locale.ENGLISH) but still fails.
formatter.format(LocalDate.of(2020, 1, 1));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The only workaround I can think of right now is not using the HOST locale provider.
FREQUENCY : always