This works with Java 11 but does not work with Java 17
DateTimeFormatter format = DateTimeFormatter.ofPattern("MMM dd, yyyy")
.withLocale(Locale.UK);
format.parse("Sep 29, 1988");
Java 17 stacktrace:
Exception in thread "main" java.time.format.DateTimeParseException: Text 'Sep 29, 1988' could not be parsed at index 0
at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2052)
at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1880)
My Java version:
openjdk version "17" 2021-09-14 LTS
OpenJDK Runtime Environment Zulu17.28 13-CA (build 17 35-LTS)
OpenJDK 64-Bit Server VM Zulu17.28 13-CA (build 17 35-LTS, mixed mode, sharing)
What has changed?
CodePudding user response:
It seems to be that in the en_GB locale, the short form of September is now "Sept", not "Sep". All the other months are the same 3 letters abbreviations as in en_US. Kind of makes sense. As a Brit, "Sep" looks wrong to me.
This is the ticket: https://bugs.openjdk.java.net/browse/JDK-8251317
It wasn't a conscious decision by the JDK authors. The locale data used by default in Java comes from Common Locale Data Repository (CLDR), which is a project by the Unicode Consortium. Newer versions of Java come with newer versions of the CLDR. So you may occasionally see a change in locale behavior. So the change you encountered is a feature, not a bug.
Yours is just one of many small tweaks.
Here's the specific change in the PR which broke it for you: https://github.com/openjdk/jdk/pull/1279/files#diff-97210acd6f77c4f4979c43445d60ba1c369f058230e41177dceca697800b1fa2R116