You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Scheduling a job to run at the same time every day with CronTrigger (eg: "0 12 * * *") results in getNextRunTime throwing ArrayIndexOutOfBoundsException when taskScheduledTime is before the target time:
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: -1
at jakarta.enterprise.concurrent.CronTrigger.nextHour(CronTrigger.java:504)
at jakarta.enterprise.concurrent.CronTrigger.next(CronTrigger.java:462)
at jakarta.enterprise.concurrent.CronTrigger.getNextRunTime(CronTrigger.java:219)
The issue can be reproduced with the following code:
public static void main(String[] args) {
var trigger = new CronTrigger("0 12 * * *", ZoneOffset.UTC);
for (var i = 0; i < 24; i++) {
try {
var taskScheduledTime = ZonedDateTime.of(2023, 4, 22, i, 0, 0, 0, trigger.getZoneId());
var next = trigger.getNextRunTime(null, taskScheduledTime);
System.err.printf("%02d: PASS (%s)\n", i, next);
} catch (Exception ex) {
System.err.printf("%02d: FAIL (%s)\n", i, ex.getMessage());
}
}
}
This produces the following output:
00: FAIL (Array index out of range: -1)
01: FAIL (Array index out of range: -1)
02: FAIL (Array index out of range: -1)
03: FAIL (Array index out of range: -1)
04: FAIL (Array index out of range: -1)
05: FAIL (Array index out of range: -1)
06: FAIL (Array index out of range: -1)
07: FAIL (Array index out of range: -1)
08: FAIL (Array index out of range: -1)
09: FAIL (Array index out of range: -1)
10: FAIL (Array index out of range: -1)
11: FAIL (Array index out of range: -1)
12: PASS (2023-04-22T12:00Z)
13: PASS (2023-04-23T12:00Z)
14: PASS (2023-04-23T12:00Z)
15: PASS (2023-04-23T12:00Z)
16: PASS (2023-04-23T12:00Z)
17: PASS (2023-04-23T12:00Z)
18: PASS (2023-04-23T12:00Z)
19: PASS (2023-04-23T12:00Z)
20: PASS (2023-04-23T12:00Z)
21: PASS (2023-04-23T12:00Z)
22: PASS (2023-04-23T12:00Z)
23: PASS (2023-04-23T12:00Z)
The text was updated successfully, but these errors were encountered:
njr-11
added a commit
to njr-11/concurrency-api
that referenced
this issue
Apr 24, 2023
Thanks for spotting this error and reporting it with the test case to reproduce. It looks like this was caused by some code that was added for detecting Daylight Saving Time which was trying to run regardless of whether the hour matched the cron expression, leading to the exception. Pull #275 adds a fix along with a test case that is based on the one provided.
Scheduling a job to run at the same time every day with CronTrigger (eg: "0 12 * * *") results in getNextRunTime throwing ArrayIndexOutOfBoundsException when taskScheduledTime is before the target time:
The issue can be reproduced with the following code:
This produces the following output:
The text was updated successfully, but these errors were encountered: