You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2026/10/17 23:31:44 UTC
(logging-log4j2) 01/01: Fix intermittent failsures in CronExpressionTest
This is an automated email from the ASF dual-hosted git repository.
rgoers pushed a commit to branch fix/CronExpressionTest
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 59ef521c687647ecc79d8e27139c6f669e897983
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Sat Oct 17 16:25:57 2026 -0700
Fix intermittent failsures in CronExpressionTest
---
.../apache/logging/log4j/core/util/CronExpressionTest.java | 6 ++++++
.../org/apache/logging/log4j/core/util/CronExpression.java | 3 ++-
src/changelog/.2.x.x/fix_cron_expression_min_date.xml | 11 +++++++++++
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/CronExpressionTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/CronExpressionTest.java
index 38c4c419ac..23528e7ce5 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/CronExpressionTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/CronExpressionTest.java
@@ -183,6 +183,12 @@ class CronExpressionTest {
assertEquals(expected, fireDate, "Dates not equal.");
}
+ @Test
+ void testMinDateIsEpoch() {
+ assertThat(CronExpression.MIN_DATE.getTime()).isZero();
+ assertThat(CronExpression.MIN_CAL.getTimeInMillis()).isZero();
+ }
+
@Test
@Timeout(value = 1, unit = TimeUnit.SECONDS)
void testPrevFireTimeAtEpochReturnsNullPromptly() throws Exception {
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CronExpression.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CronExpression.java
index 6c93647a45..04a4bf159f 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CronExpression.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/CronExpression.java
@@ -257,7 +257,8 @@ public final class CronExpression {
public static final Calendar MIN_CAL = Calendar.getInstance();
static {
- MIN_CAL.set(1970, 0, 1);
+ // The epoch, independent of the time of day and the default time zone
+ MIN_CAL.setTimeInMillis(0);
}
public static final Date MIN_DATE = MIN_CAL.getTime();
diff --git a/src/changelog/.2.x.x/fix_cron_expression_min_date.xml b/src/changelog/.2.x.x/fix_cron_expression_min_date.xml
new file mode 100644
index 0000000000..cdb1b82979
--- /dev/null
+++ b/src/changelog/.2.x.x/fix_cron_expression_min_date.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns="https://logging.apache.org/xml/ns"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ https://logging.apache.org/xml/ns
+ https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
+ type="fixed">
+ <description format="asciidoc">
+ Fix `CronExpression.MIN_DATE` to be the epoch instead of depending on the JVM start time and default time zone.
+ </description>
+</entry>