Skip to content

Commit

Permalink
fix(quartz): avoid NPE when scheduled method identity has been change…
Browse files Browse the repository at this point in the history
…d/renamed

Fixes #24931
  • Loading branch information
machi1990 committed May 5, 2022
1 parent 4df39b6 commit 626f59e
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ public QuartzScheduler(SchedulerContext context, QuartzSupport quartzSupport, Sc
org.quartz.Trigger trigger = triggerBuilder.build();
org.quartz.Trigger oldTrigger = scheduler.getTrigger(trigger.getKey());
if (oldTrigger != null) {
scheduler.rescheduleJob(trigger.getKey(),
triggerBuilder.startAt(oldTrigger.getNextFireTime()).build());
trigger = triggerBuilder.startAt(oldTrigger.getNextFireTime()).build();
scheduler.rescheduleJob(trigger.getKey(), trigger);
LOGGER.debugf("Rescheduled business method %s with config %s", method.getMethodDescription(),
scheduled);
} else if (!scheduler.checkExists(jobDetail.getKey())) {
Expand All @@ -292,7 +292,8 @@ public QuartzScheduler(SchedulerContext context, QuartzSupport quartzSupport, Sc
oldTrigger = scheduler.getTrigger(new TriggerKey(identity + "_trigger", Scheduler.class.getName()));
if (oldTrigger != null) {
scheduler.deleteJob(jobDetail.getKey());
scheduler.scheduleJob(jobDetail, triggerBuilder.startAt(oldTrigger.getNextFireTime()).build());
trigger = triggerBuilder.startAt(oldTrigger.getNextFireTime()).build();
scheduler.scheduleJob(jobDetail, trigger);
LOGGER.debugf(
"Rescheduled business method %s with config %s due to Trigger '%s' record being renamed after removal of '_trigger' suffix",
method.getMethodDescription(),
Expand Down Expand Up @@ -558,7 +559,7 @@ static class InvokerJob implements Job {

@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
if (trigger.invoker != null) { // could be null from previous runs
if (trigger != null && trigger.invoker != null) { // could be null from previous runs
if (trigger.invoker.isBlocking()) {
try {
trigger.invoker.invoke(new QuartzScheduledExecution(trigger, jobExecutionContext));
Expand All @@ -579,6 +580,11 @@ public void handle(Void event) {
}
});
}
} else {
String jobName = jobExecutionContext.getJobDetail().getKey().getName();
LOGGER.warnf("Unable to find corresponding Quartz trigger for job %s. " +
"Update your Quartz table by removing all phantom jobs or make sure that they there is a " +
"Scheduled method with the identity matching the job's name", jobName);
}
}
}
Expand Down

0 comments on commit 626f59e

Please sign in to comment.