Skip to content

Commit c7b9784

Browse files
author
zhaomeng
committed
Fix CronTrigger equals/hashCode to include zoneId
Ensure CronTrigger instances with the same cron expression but different time zones are no longer considered equal.
1 parent 6303fd0 commit c7b9784

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

spring-context/src/main/java/org/springframework/scheduling/support/CronTrigger.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
import java.time.Instant;
2020
import java.time.ZoneId;
2121
import java.time.ZonedDateTime;
22+
import java.util.Objects;
2223
import java.util.TimeZone;
2324

2425
import org.jspecify.annotations.Nullable;
2526

2627
import org.springframework.scheduling.Trigger;
2728
import org.springframework.scheduling.TriggerContext;
2829
import org.springframework.util.Assert;
29-
import org.springframework.util.ObjectUtils;
3030

3131
/**
3232
* {@link Trigger} implementation for cron expressions. Wraps a
@@ -147,12 +147,12 @@ Instant determineInitialTimestamp(TriggerContext triggerContext) {
147147
public boolean equals(@Nullable Object other) {
148148
return (this == other || (other instanceof CronTrigger that &&
149149
this.expression.equals(that.expression) &&
150-
ObjectUtils.nullSafeEquals(this.zoneId, that.zoneId)));
150+
Objects.equals(this.zoneId, that.zoneId)));
151151
}
152152

153153
@Override
154154
public int hashCode() {
155-
return ObjectUtils.nullSafeHash(this.expression, this.zoneId);
155+
return Objects.hash(this.expression, this.zoneId);
156156
}
157157

158158
@Override

spring-context/src/test/java/org/springframework/scheduling/support/CronTriggerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ void daylightSavingMissingHour() {
748748
}
749749

750750
@Test
751-
void equalsAndHashCodeConsidersZoneId() {
751+
void equalsAndHashCodeConsiderZoneId() {
752752
String cron = "0 0 9 * * *";
753753
CronTrigger amsterdam = new CronTrigger(cron, ZoneId.of("Europe/Amsterdam"));
754754
CronTrigger newYork = new CronTrigger(cron, ZoneId.of("America/New_York"));

0 commit comments

Comments
 (0)