[LOG4J2-issue-3660] Add comprehensive unit tests for CronExpression daylight saving and scheduling logic#4081
Open
ramanathan1504 wants to merge 1 commit intoapache:2.xfrom
Open
[LOG4J2-issue-3660] Add comprehensive unit tests for CronExpression daylight saving and scheduling logic#4081ramanathan1504 wants to merge 1 commit intoapache:2.xfrom
ramanathan1504 wants to merge 1 commit intoapache:2.xfrom
Conversation
Enhance CronExpression to handle Daylight Saving Time transitions in fire time calculations
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.
Issue #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.