Uploaded image for project: 'Quartz Scheduler (Historical - Do Not File New Issues Here - See GitHub)'
  1. Quartz Scheduler (Historical - Do Not File New Issues Here - See GitHub)
  2. QTZ-332

TriggerBuilder.build causes an exception when building a CalendarIntervalTrigger with an end time that is in the past.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: 2 Major
    • Resolution: Duplicate
    • Affects Version/s: 2.0.2
    • Fix Version/s: 2.1.7
    • Component/s: Triggers
    • Labels:
      None
    • Terracotta Target:
      Unknown

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ljacomet Louis Jacomet Jacomet
                Reporter:
                harishk Harish Kantamneni
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: