Repository navigation
fix: honor GlobalConfiguration.locale for java.util.Date string conversion - #1311
yebuguntang wants to merge 1 commit into
Conversation
…rsion DateStringConverter used SimpleDateFormat with the JVM default locale, while all java.time converters honor the configured locale. Pass the locale through new DateUtils format/parseDate overloads and key the SimpleDateFormat cache by locale as well as pattern. Old signatures keep their behavior by falling back to the JVM default format locale. Fixes apache#1040
Mikkey-f
left a comment
There was a problem hiding this comment.
Thanks @yebuguntang — reproduced and verified locally (Windows 11, JDK 17). This closes the remaining java.util.Date gap from #1040.
Root cause: DateStringConverter never read GlobalConfiguration.locale; and DateUtils's SimpleDateFormat cache was keyed by pattern only, so wiring a locale through without re-keying would silently reuse a formatter built for another locale on the same thread.
Verification
Green (head 07645b31):
DateStringConverterTest7/7,DateUtilsTest94/94 (101 total)- full suite:
fesod-sheet1,807 +fesod-common60 = 1,867 tests, 0 failures/errors spotless:checkclean
Red side:
- Reverting only
DateStringConverter→convertToExcelDataHonorsConfiguredLocalefails withexpected: <星期一 16 十一月 2026> but was: <Monday 16 November 2026>, and the read test errors — this pins the converter wiring. - Keeping the new signatures but resolving the locale from
Locale.getDefault(Locale.Category.FORMAT)insidegetCacheDateFormat→test_formatDate_respectsLocalefails,test_parseDate_respectsLocaleandtest_dateFormatCache_isBoundederror, and both converter tests fail — this shows the locale-first cache key is required, not cosmetic.
Compatibility: the two-arg overloads delegate with null → Locale.getDefault(Locale.Category.FORMAT), and the only production callers are DateStringConverter and the DateUtils tests, so users who never call .locale(...) see no behavior change. The java.util.Date path now matches the java.time converters.
Non-blocking
StringNumberConverter:62still formats a numeric date serial into aStringfield throughDateUtils.format(BigDecimal, ...), which takes no locale; with a pattern likedd MMMM yyyythe month name still follows the JVM default even when.locale()is set. Different converter/target type from #1040, so probably fine to leave out of this PR — but a follow-up issue may be worth it.- The tests are unit-level; a small round-trip test (write and read a bean with both
DateandLocalDateTimefields under.locale(Locale.CHINESE)) would cover the user-facing scenario from #1040 through the realWriteContext/AnalysisContextwiring. - Optional: a converter-level test with
globalConfiguration.setLocale(null)would pin the fallback path end-to-end.
skytin1004
left a comment
There was a problem hiding this comment.
Hi @yebuguntang, I verified this locally and didn't find any issues. LGTM.
Purpose of the pull request
Closed: #1040
java.util.Datestring conversion ignoredGlobalConfiguration.locale:DateStringConvertercalledDateUtils.format(Date, ...)/parseDate(...)without a locale, soSimpleDateFormatalways used the JVM default locale. Everyjava.timeconverter already passes the configured locale, so a POJO with both aDateand aLocalDateTimefield got localized text for only one of them. This PR makesjava.util.Datefollow the same rule. Happy to adjust if maintainers consider the old split intentional.What's changed?
DateUtils.format(Date, String, Locale)andDateUtils.parseDate(String, String, Locale)overloads. The existing signatures delegate withnull, which still resolves toLocale.getDefault(Locale.Category.FORMAT), so behavior is unchanged for all current callers.SimpleDateFormatthread-local cache by locale first, then pattern, reusing the bounded FIFO maps already used by theDateTimeFormattercache. Without this, two locales sharing a pattern would reuse the formatter built for the first locale.globalConfiguration.getLocale()fromDateStringConverterin both read and write directions.SimpleDateFormatwith the target locale, so the tests hold on JDK 8 (JRE locale data) and JDK 9+ (CLDR).No website documentation change:
GlobalConfiguration.localeis already documented as affecting date/number formatting; this fix makes that statement true forjava.util.Date.Verification
./mvnw -o clean package -pl fesod-common,fesod-shaded,fesod-sheet: BUILD SUCCESS, 1807 tests, 0 failures/errors (JDK 21).DateStringConverterTest+DateUtilsTest: 101 tests pass on JDK 21 and on JDK 8.spotless:checkandgit diff --checkare clean.Checklist