Include zone ID in CronTrigger's equals/hashCode implementations#36871
Closed
zmovo wants to merge 2 commits into
Closed
Include zone ID in CronTrigger's equals/hashCode implementations#36871zmovo wants to merge 2 commits into
zmovo wants to merge 2 commits into
Conversation
CronTrigger carries an optional ZoneId since 5.3 that affects nextExecution, but equals and hashCode only considered the cron expression. Include zoneId in both methods. Signed-off-by: zhaomeng <zhaomeng1.vendor@sensetime.com>
sbrannen
requested changes
Jun 4, 2026
sbrannen
left a comment
Member
There was a problem hiding this comment.
Thanks for the PR.
I've requested a few minor changes.
Author
Thanks for the feedback! I've updated the PR accordingly. Could you please take another look? |
Ensure CronTrigger instances with the same cron expression but different time zones are no longer considered equal. Signed-off-by: zhaomeng <zhaomeng1.vendor@sensetime.com> Co-authored-by: Cursor <cursoragent@cursor.com>
c7b9784 to
45a013e
Compare
sbrannen
added a commit
that referenced
this pull request
Jun 5, 2026
Member
|
This has been merged into Thanks |
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.
By default,
CronTrigger#equalsand#hashCodeconsider only the wrappedCronExpression. Since 5.3,CronTriggeralso carries an optionalZoneIdthat is used in
nextExecution()when a time zone is configured explicitly.Two triggers built with the same cron pattern but different zones can therefore
produce different next execution times while still comparing as equal and
sharing the same hash code.
This causes incorrect deduplication when triggers are stored in a
Setor usedas
Mapkeys, and breaks the generalObjectcontract for a type whose runtimebehavior depends on both the expression and the zone.
This PR includes
zoneIdinequalsandhashCode, usingObjectUtils.nullSafeEqualsandObjectUtils.nullSafeHashso that triggerswith a
nullzone (the default constructor) remain equal to each other butdistinct from triggers with an explicit zone.
This does not change trigger scheduling behavior or how
nextExecutionselects a zone at runtime; it only corrects value-based equality for triggers
that differ solely by time zone configuration.
It also adds a regression test in
CronTriggerTests#equalsAndHashCodeConsidersZoneId.Test plan
./gradlew :spring-context:test --tests "org.springframework.scheduling.support.CronTriggerTests.equalsAndHashCodeConsidersZoneId"