Closed
Description
Scott Albertine opened SPR-14480 and commented
I've found a cron line and timestamp pair that violates sane ordering of the CronSequenceGenerator#next(Date) function.
Demonstration test below:
@Test
public void demonstrateBug() {
//I've found a cron line and timestamp pair that violates sane ordering of the CronSequenceGenerator#next(Date) function.
long workingTimeStamp = 1468850400000L; //18 Jul 2016 14:00:00 GMT
long problemTimeStamp = 1468867460443L; //18 Jul 2016 18:44:20.443 GMT
String cronLine = "*/3 * 13 * * *"; //cron line that causes issues, found by fuzz testing
CronSequenceGenerator generator = new CronSequenceGenerator(cronLine, TimeZone.getTimeZone("UTC")); //standard generator using that cron line
Date correctNextRun = generator.next(new Date(workingTimeStamp));
long correctNextRunTime = correctNextRun.getTime(); //correctly finds 1468933200000L
//demonstrate that the problem timestamp is between the working timestamp and its next run
Assert.assertTrue(workingTimeStamp < problemTimeStamp);
Assert.assertTrue(problemTimeStamp < correctNextRunTime);
//this means that, since the problem timestamp is between the working one and its next run, getting the next run of the problem timestamp should result in the SAME next run as the one from the working timestamp
Date faultyNextRun = generator.next(new Date(problemTimeStamp));
long faultyNextRunTime = faultyNextRun.getTime(); //incorrectly finds 1468933221000L
Assert.assertEquals(correctNextRunTime, faultyNextRunTime); //THIS FAILS, demonstrating the bug.
}
Affects: 4.3.1
Issue Links:
- CronSequenceGenerator.next() is not implemented as documented [SPR-14589] #19158 CronSequenceGenerator.next() is not implemented as documented