This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/2.x by this push:
new 769b924917 [LOG4J2-3805]
NamedInstantPatternTest#compatibilityOfLegacyPattern fails in timezones with
minute offsets (e.g., GMT+05:30) (#3888)
769b924917 is described below
commit 769b9249176b69ad4474fc4bd831dec67775c953
Author: Ramanathan <[email protected]>
AuthorDate: Fri Aug 22 02:00:08 2025 +0530
[LOG4J2-3805] NamedInstantPatternTest#compatibilityOfLegacyPattern fails in
timezones with minute offsets (e.g., GMT+05:30) (#3888)
* [LOG4J2-3805] Skip compatibilityOfLegacyPattern test for fractional
timezone offsets
The compatibilityOfLegacyPattern test fails in environments where the system
default timezone has a non-zero minute offset (e.g., Asia/Kolkata,
Asia/Kathmandu).
Root cause:
- SimpleDateFormat's X pattern truncates fractional offsets (e.g., +05:30 →
+05).
- DateTimeFormatter's X pattern preserves the minutes (+05:30).
Since Log4j intentionally follows DateTimeFormatter’s behavior, the test
should
not assert equivalence in such environments.
This change adds an assumption to skip the test when the system timezone
offset
is not a whole hour. This ensures deterministic builds for contributors in
all
regions, while still verifying correctness in whole-hour zones.
Closes #3805
* LOG4J2-3885: Add test for ISO8601_OFFSET_DATE_TIME_HH with system default
zone
Ensure legacy and modern formatting produce consistent results
when the system default zone offset is a whole hour.
Skip the test otherwise using assumptions.
---
.../log4j/core/pattern/NamedInstantPatternTest.java | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/NamedInstantPatternTest.java
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/NamedInstantPatternTest.java
index bbe5e6e45e..e4065438cb 100644
---
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/NamedInstantPatternTest.java
+++
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/NamedInstantPatternTest.java
@@ -17,8 +17,11 @@
package org.apache.logging.log4j.core.pattern;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assumptions.assumeThat;
import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZoneOffset;
import org.apache.logging.log4j.core.time.MutableInstant;
import
org.apache.logging.log4j.core.util.internal.instant.InstantPatternFormatter;
import org.junit.jupiter.params.ParameterizedTest;
@@ -29,6 +32,15 @@ class NamedInstantPatternTest {
@ParameterizedTest
@EnumSource(NamedInstantPattern.class)
void compatibilityOfLegacyPattern(NamedInstantPattern namedPattern) {
+ if (namedPattern == NamedInstantPattern.ISO8601_OFFSET_DATE_TIME_HH) {
+ ZoneOffset offset =
ZoneId.systemDefault().getRules().getOffset(Instant.now());
+ assumeThat(offset.getTotalSeconds() % 3600 == 0)
+ .withFailMessage(
+ "Skipping test: ISO8601_OFFSET_DATE_TIME_HH
requires a whole-hour offset, but system offset is %s",
+ offset)
+ .isTrue();
+ }
+
InstantPatternFormatter legacyFormatter =
InstantPatternFormatter.newBuilder()
.setPattern(namedPattern.getLegacyPattern())
.setLegacyFormattersEnabled(true)
@@ -40,6 +52,8 @@ class NamedInstantPatternTest {
Instant javaTimeInstant = Instant.now();
MutableInstant instant = new MutableInstant();
instant.initFromEpochSecond(javaTimeInstant.getEpochSecond(),
javaTimeInstant.getNano());
-
assertThat(legacyFormatter.format(instant)).isEqualTo(formatter.format(instant));
+ String legacy = legacyFormatter.format(instant);
+ String modern = formatter.format(instant);
+ assertThat(legacy).isEqualTo(modern);
}
}