java.lang.IllegalArgumentException: End time cannot be before start time

Terracotta Project Issue Tracker | Harish Kantamneni | 4 years ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    When using the TriggerBuilder class to build a CalendarIntervalTrigger with an end time that is in the past, an IllegalArgumentException is thrown indicating that end time cannot be before the start time, even though that is not the case. Repro: TriggerBuilder<CalendarIntervalTrigger> tb = TriggerBuilder.newTrigger() .withSchedule( CalendarIntervalScheduleBuilder.calendarIntervalSchedule().withIntervalInDays(1)) .startAt(new Instant("2004-11-20").toDate()) .endAt(new Instant("2005-11-20").toDate()); .build() Resulting exception: java.lang.IllegalArgumentException: End time cannot be before start time at org.quartz.impl.triggers.CalendarIntervalTriggerImpl.setEndTime(CalendarIntervalTriggerImpl.java:292) at org.quartz.TriggerBuilder.build(TriggerBuilder.java:97) Note that the start time here is "2004-11-20" and the end time here is "2005-11-20" and so should not result in this exception. Fix: It appears that the default start time for CalendarIntervalTrigger is "now" or more precisely the instant when getStartTime() is first accessed. Given this behavior, if an end time in the past is set before setting a start time, then this end time is compared with "now" and the above described exception is thrown. So, in order to be able to set a past end time on this trigger, the start time needs to be set first. But the TriggerBuilder.build() method sets the end time before the start time. So the fix is to modify TriggerBuilder.build() to set the start time for a trigger first before setting its end time.

    Terracotta Project Issue Tracker | 4 years ago | Harish Kantamneni
    java.lang.IllegalArgumentException: End time cannot be before start time
  2. 0

    When using the TriggerBuilder class to build a CalendarIntervalTrigger with an end time that is in the past, an IllegalArgumentException is thrown indicating that end time cannot be before the start time, even though that is not the case. Repro: TriggerBuilder<CalendarIntervalTrigger> tb = TriggerBuilder.newTrigger() .withSchedule( CalendarIntervalScheduleBuilder.calendarIntervalSchedule().withIntervalInDays(1)) .startAt(new Instant("2004-11-20").toDate()) .endAt(new Instant("2005-11-20").toDate()); .build() Resulting exception: java.lang.IllegalArgumentException: End time cannot be before start time at org.quartz.impl.triggers.CalendarIntervalTriggerImpl.setEndTime(CalendarIntervalTriggerImpl.java:292) at org.quartz.TriggerBuilder.build(TriggerBuilder.java:97) Note that the start time here is "2004-11-20" and the end time here is "2005-11-20" and so should not result in this exception. Fix: It appears that the default start time for CalendarIntervalTrigger is "now" or more precisely the instant when getStartTime() is first accessed. Given this behavior, if an end time in the past is set before setting a start time, then this end time is compared with "now" and the above described exception is thrown. So, in order to be able to set a past end time on this trigger, the start time needs to be set first. But the TriggerBuilder.build() method sets the end time before the start time. So the fix is to modify TriggerBuilder.build() to set the start time for a trigger first before setting its end time.

    Terracotta Project Issue Tracker | 4 years ago | Harish Kantamneni
    java.lang.IllegalArgumentException: End time cannot be before start time

    Root Cause Analysis

    1. java.lang.IllegalArgumentException

      End time cannot be before start time

      at org.quartz.impl.triggers.CalendarIntervalTriggerImpl.setEndTime()
    2. quartz
      TriggerBuilder.build
      1. org.quartz.impl.triggers.CalendarIntervalTriggerImpl.setEndTime(CalendarIntervalTriggerImpl.java:292)
      2. org.quartz.TriggerBuilder.build(TriggerBuilder.java:97)
      2 frames