Skip to content

Commit

Permalink
Issue #35 NullPointerException when getNextRunTime is null
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Rauh <nathan.rauh@us.ibm.com>
  • Loading branch information
njr-11 committed Oct 21, 2021
1 parent ba0c721 commit 9c87d20
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public interface ZonedTrigger extends Trigger {
*/
public default Date getNextRunTime(LastExecution lastExecutionInfo, Date taskScheduledTime) {
ZonedDateTime nextTime = getNextRunTime(lastExecutionInfo, taskScheduledTime.toInstant().atZone(getZoneId()));
return Date.from(nextTime.toInstant());
return nextTime == null ? null : Date.from(nextTime.toInstant());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,22 @@ public void testLastExecutionDefaultImplementation() {
assertNotNull(lastExecWithNulls.getScheduledStart());
}

/**
* Ensure that the default method for getNextRunTime(LastExecution, Date) can
* cope with a null being returned by getNextRunTime(LastExecution, ZonedDateTime).
*/
@Test
public void testNullNextRunTime() {
ZonedTrigger trigger = new ZonedTrigger() {
@Override
public ZonedDateTime getNextRunTime(LastExecution lastExec, ZonedDateTime taskScheduledTime) {
return null;
}
};

assertNull(trigger.getNextRunTime(null, new Date()));
}

/**
* Test the default implementation of ZonedTrigger.skipRun(LastExecution, Date),
* which ought to delegate to skipRun(LastExecution, ZonedDateTime).
Expand Down

0 comments on commit 9c87d20

Please sign in to comment.