Skip to content

CronSequenceGenerator.next() returns incorrect time [SPR-14480] #19049

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: bulk-closedAn outdated, unresolved issue that's closed in bulk as part of a cleaning process

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions