Skip to content

Fix DatePatternConverter locale parsing when timezone is omitted#4130

Open
ramanathan1504 wants to merge 2 commits into
2.xfrom
fix-4129-locale-without-timezone
Open

Fix DatePatternConverter locale parsing when timezone is omitted#4130
ramanathan1504 wants to merge 2 commits into
2.xfrom
fix-4129-locale-without-timezone

Conversation

@ramanathan1504
Copy link
Copy Markdown
Contributor

Fixes #4129

DatePatternConverter incorrectly interpreted locale-like second arguments (for example de-DE) as timezone IDs when no timezone was provided.
This caused patterns like %d{dd-MMMM-yyyy}{de-DE} to use the JVM default locale instead of the requested locale, producing incorrect localized month names.
This change tightens locale detection so locale tags are correctly recognized in the 2-argument form, while preserving existing behavior for the 3-argument form %d{pattern}{timezone}{locale}.

private static final Set<String> UPPERCASE_TIME_ZONE_IDS = AVAILABLE_TIME_ZONE_IDS.stream()
.map(id -> id.toUpperCase(Locale.ROOT))
.collect(Collectors.toSet());
private static final String LOCALE_LANGUAGE_ONLY_PATTERN = "[a-zA-Z]{2}";
Copy link
Copy Markdown

@andrei-ivanov andrei-ivanov May 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these could be a Pattern instead, to avoid recompiling it on every String.matches call

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

Log4J pattern layout inconsistencies when locale is specified

2 participants