Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid NPE when scheduled method identity has been renamed #25407

Merged
merged 1 commit into from
May 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-assign the trigger with the proper start time as it is used in

scheduledTasks.put(identity, new QuartzTrigger(trigger, invoker,

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();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 there is a " +
"Scheduled method with the identity matching the job's name", jobName);
}
}
}
Expand Down