Skip to content

fix: InstantPatternLegacyFormatter precision for legacy n patterns#4220

Open
SebTardif wants to merge 1 commit into
apache:2.xfrom
SebTardif:fix/3816-legacy-pattern-precision
Open

fix: InstantPatternLegacyFormatter precision for legacy n patterns#4220
SebTardif wants to merge 1 commit into
apache:2.xfrom
SebTardif:fix/3816-legacy-pattern-precision

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

What Problem This Solves

InstantPatternLegacyFormatter computed precision by constructing InstantPatternDynamicFormatter with the legacy pattern string. Legacy FixedDateFormat patterns use n for variable-length fractional seconds. DateTimeFormatter treats n as always nano-of-second, so patterns such as yyyy-MM-dd HH:mm:ss,nnnnnn were classified as NANOS instead of MICROS, breaking cache invalidation for legacy formatters.

Evidence

Issue #3816. Approach matches ppkarwasz's fix on main (nS before precision detection), which was not present on 2.x.

Red-green

Without the fix:

expected: Micros
 but was: Nanos

With the fix:

export JAVA_HOME=$(/usr/libexec/java_home -v 17)
./mvnw -pl log4j-core,log4j-core-test -am test \
  -Dtest=InstantPatternLegacyFormatterPrecisionTest,NamedInstantPatternTest \
  -Dsurefire.failIfNoSpecifiedTests=false

InstantPatternLegacyFormatterPrecisionTest: 2 passed
NamedInstantPatternTest: 21 passed (also asserts legacy/modern precision parity)

Summary

…terns

Legacy FixedDateFormat patterns use n for variable-length fractional seconds.
DateTimeFormatter treats n as always nano-of-second, so precision detection
via InstantPatternDynamicFormatter classified microsecond patterns as NANOS
and broke cache invalidation.

Map legacy n to S before precision detection (same approach as ppkarwasz on
main). Red-green: yyyy-MM-dd HH:mm:ss,nnnnnn is MICROS with the fix, NANOS
without.

Fixes apache#3816

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
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.

InstantPatternLegacyFormatter computes precision incorrectly

1 participant