From 0e74800c318779844bff1a51dc028af89744facc Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Sat, 27 Jul 2024 17:11:27 +0100 Subject: [PATCH] Avoid a possible NPE during application stop --- .../io/quarkus/runtime/ApplicationLifecycleManager.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java b/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java index 48c18f868b7b2..d16e5ff7e94af 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java @@ -429,13 +429,15 @@ public void run() { } finally { stateLock.unlock(); } - if (currentApplication.isStarted()) { + //take a reliable reference before changing the application state: + final Application app = currentApplication; + if (app.isStarted()) { // On CLI apps, SIGINT won't call io.quarkus.runtime.Application#stop(), // making the awaitShutdown() below block the application termination process // It should be a noop if called twice anyway - currentApplication.stop(); + app.stop(); } - currentApplication.awaitShutdown(); + app.awaitShutdown(); currentApplication = null; System.out.flush(); System.err.flush();