Repository: quarkusio/quarkus
Issue: NullPointerException with Quartz and Quarkus 2.8.0.Final when a job identity is changed

### Describe the bug

After updating to Quarkus 2.8.0.Final, one of our scheduled tasks failed with an exception I've not seen before and that seems to be coming from Quarkus:

```
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.NullPointerException: Cannot read field "invoker" because "this.trigger" is null]
	at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: java.lang.NullPointerException: Cannot read field "invoker" because "this.trigger" is null
	at io.quarkus.quartz.runtime.QuartzScheduler$InvokerJob.execute(QuartzScheduler.java:553)
	at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
```

Application is deployed as an uber-jar.

### Expected behavior

No NullPointerException is thrown when scheduling jobs

### Actual behavior

_No response_

### How to Reproduce?

_No response_

### Output of `uname -a` or `ver`

RHEL 8 Linux

### Output of `java -version`

17.0.2

### GraalVM version (if different from Java)

_No response_

### Quarkus version or git rev

2.8.0.Final

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)

Gradle 7.4.1

### Additional information

_No response_

Changed files:
extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzScheduler.java

diff --git a/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzScheduler.java b/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzScheduler.java
index ec68f58ae00..22e65c5c55b 100644
--- a/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzScheduler.java
+++ b/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzScheduler.java
@@ -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())) {
@@ -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(),
@@ -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));
@@ -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);
             }
         }
     }