Improve CronExpression tests to cover daylight saving and scheduling logic#4081
Open
ramanathan1504 wants to merge 6 commits intoapache:2.xfrom
Open
Improve CronExpression tests to cover daylight saving and scheduling logic#4081ramanathan1504 wants to merge 6 commits intoapache:2.xfrom
CronExpression tests to cover daylight saving and scheduling logic#4081ramanathan1504 wants to merge 6 commits intoapache:2.xfrom
Conversation
CronExpression tests to cover daylight saving and scheduling logic
vy
requested changes
Apr 23, 2026
Member
vy
left a comment
There was a problem hiding this comment.
Reviewed with @ppkarwasz — changes look good. I've triggered the CI, keep an eye on it and address its failures, please. Could you also add a changelog entry referencing to both the Issue and PR IDs?
Contributor
Author
@vy |
Enhance CronExpression to handle Daylight Saving Time transitions in fire time calculations
408a6c8 to
7209078
Compare
… transition tests
vy
approved these changes
Apr 24, 2026
vy
requested changes
Apr 24, 2026
vy
reviewed
Apr 24, 2026
vy
approved these changes
Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3660
Root cause (what was going wrong)
There were three related edge cases:
Strict-after boundary in
getTimeAftergetTimeAftermust move to the next second before evaluation.+1mscan collapse back to the same second after millisecond truncation and return the same fire time again.Millisecond input handling in
getPrevFireTime...00.201).getPrevFireTimecould resolve to the previous day around DST fallback boundaries, which can trigger an extra rollover.Spring-forward (23-hour day) reverse-search step
Fix implemented
In
log4j-core/src/main/java/org/apache/logging/log4j/core/util/CronExpression.java:getTimeAfter(...): keep strict next-second behavior (+1000ms).getPrevFireTime(...): for inputs with millisecond fraction, shift by+999msbefore delegating togetTimeBefore(...).findMinIncrement(): for day-level fallback increment, use 23h minimum step to remain DST-safe on spring-forward days.Validation
log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/CronExpressionTest.javanow includes/contains DST cases for:Australia/Sydney)America/Santiago)Australia/Sydney)Current result locally:
CronExpressionTest: 16 run, 0 failuresThis addresses the “twice-a-year” DST rollover corruption path you described, including both fallback ambiguity and spring-forward short-day behavior.