-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
P4
-
Affects Version/s: 25
-
Component/s: core-libs
-
Fix Understood
-
generic
-
os_x
When running a simple date/time formatting test under the zh_TW (Taiwanese/Traditional Chinese) locale on macOS with the system property -Djava.locale.providers=HOST, the application throws an IllegalArgumentException due to an unrecognized pattern character 'B' in the date/time pattern returned by the host locale provider.
The same test passes on older version of macOS(14.4) but on newer version (15.6.1) it fails.
————————————————————————
Steps to Reproduce:
Create the test file DateFormatTest.java:
import java.util.*;
import java.text.*;
import java.time.chrono.*;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
public class DateFormatTest {
private Locale locale;
private Calendar calendar;
public DateFormatTest() {
locale = Locale.getDefault();
calendar = Calendar.getInstance(locale);
}
public void printDateTime(int dateStyle, int timeStyle) {
DateFormat df = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
System.out.print(df.format(calendar.getTime()));
SimpleDateFormat sdf = (SimpleDateFormat) df; // cast to SimpleDateFormat
System.out.println(" (" + sdf.toPattern() + ")");
}
void printInfo() {
System.out.println("Locale: " + locale);
System.out.println("Calendar: " + calendar.getCalendarType());
}
public static void main(String[] args) {
DateFormatTest test = new DateFormatTest();
test.printInfo();
// full format
System.out.print("FULL:FULL: ");
test.printDateTime(DateFormat.FULL, DateFormat.FULL);
// long format
System.out.print("LONG:LONG: ");
test.printDateTime(DateFormat.LONG, DateFormat.LONG);
// medium format
System.out.print("MEDIUM:MEDIUM: ");
test.printDateTime(DateFormat.MEDIUM, DateFormat.MEDIUM);
// short format
System.out.print("SHORT:SHORT: ");
test.printDateTime(DateFormat.SHORT, DateFormat.SHORT);
}
}
2. Compile and run with:
javac DateFormatTest.java
java -Djava.locale.providers=HOST DateFormatTest
Actual Result:
Locale: zh_TW_#Hant Calendar: gregory FULL:FULL: Exception in thread "main" java.lang.IllegalArgumentException: Illegal pattern character 'B' at java.base/java.text.SimpleDateFormat.compile(SimpleDateFormat.java:849) at java.base/java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:657) at java.base/java.text.SimpleDateFormat.(SimpleDateFormat.java:628) at java.base/sun.util.locale.provider.HostLocaleProviderAdapterImpl$2.getDateTimeInstance(HostLocaleProviderAdapterImpl.java:340) at java.base/java.text.DateFormat.get(DateFormat.java:848) at java.base/java.text.DateFormat.get(DateFormat.java:832) at java.base/java.text.DateFormat.getDateTimeInstance(DateFormat.java:619) at DateFormatTest.printDateTime(DateFormatTest.java:18) at DateFormatTest.main(DateFormatTest.java:37)
Expected Result:
The date and time should print successfully without exception, as they do:
when -Djava.locale.providers=HOST is not specified.
Additional Information:
The 'B' pattern character represents the “day period” in CLDR/Unicode date patterns, but it is not supported by SimpleDateFormat.
The macOS HostLocaleProviderAdapterImpl seems to return this pattern directly from the host system without sanitizing or mapping unsupported pattern characters.
The issue likely resides in the macOS-specific branch of HostLocaleProviderAdapterImpl.
The same test passes on older version of macOS(14.4) but on newer version (15.6.1) it fails.
————————————————————————
Steps to Reproduce:
Create the test file DateFormatTest.java:
import java.util.*;
import java.text.*;
import java.time.chrono.*;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
public class DateFormatTest {
private Locale locale;
private Calendar calendar;
public DateFormatTest() {
locale = Locale.getDefault();
calendar = Calendar.getInstance(locale);
}
public void printDateTime(int dateStyle, int timeStyle) {
DateFormat df = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
System.out.print(df.format(calendar.getTime()));
SimpleDateFormat sdf = (SimpleDateFormat) df; // cast to SimpleDateFormat
System.out.println(" (" + sdf.toPattern() + ")");
}
void printInfo() {
System.out.println("Locale: " + locale);
System.out.println("Calendar: " + calendar.getCalendarType());
}
public static void main(String[] args) {
DateFormatTest test = new DateFormatTest();
test.printInfo();
// full format
System.out.print("FULL:FULL: ");
test.printDateTime(DateFormat.FULL, DateFormat.FULL);
// long format
System.out.print("LONG:LONG: ");
test.printDateTime(DateFormat.LONG, DateFormat.LONG);
// medium format
System.out.print("MEDIUM:MEDIUM: ");
test.printDateTime(DateFormat.MEDIUM, DateFormat.MEDIUM);
// short format
System.out.print("SHORT:SHORT: ");
test.printDateTime(DateFormat.SHORT, DateFormat.SHORT);
}
}
2. Compile and run with:
javac DateFormatTest.java
java -Djava.locale.providers=HOST DateFormatTest
Actual Result:
Locale: zh_TW_#Hant Calendar: gregory FULL:FULL: Exception in thread "main" java.lang.IllegalArgumentException: Illegal pattern character 'B' at java.base/java.text.SimpleDateFormat.compile(SimpleDateFormat.java:849) at java.base/java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:657) at java.base/java.text.SimpleDateFormat.(SimpleDateFormat.java:628) at java.base/sun.util.locale.provider.HostLocaleProviderAdapterImpl$2.getDateTimeInstance(HostLocaleProviderAdapterImpl.java:340) at java.base/java.text.DateFormat.get(DateFormat.java:848) at java.base/java.text.DateFormat.get(DateFormat.java:832) at java.base/java.text.DateFormat.getDateTimeInstance(DateFormat.java:619) at DateFormatTest.printDateTime(DateFormatTest.java:18) at DateFormatTest.main(DateFormatTest.java:37)
Expected Result:
The date and time should print successfully without exception, as they do:
when -Djava.locale.providers=HOST is not specified.
Additional Information:
The 'B' pattern character represents the “day period” in CLDR/Unicode date patterns, but it is not supported by SimpleDateFormat.
The macOS HostLocaleProviderAdapterImpl seems to return this pattern directly from the host system without sanitizing or mapping unsupported pattern characters.
The issue likely resides in the macOS-specific branch of HostLocaleProviderAdapterImpl.
- relates to
-
JDK-8247781 Day periods support
-
- Resolved
-
- links to
-
Review(master)
openjdk/jdk/28181