From 80bf54c370c6ccbcede821834dc19c5eb910d451 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Tue, 27 Aug 2024 15:14:34 +0300 Subject: [PATCH] Avoid `NullPointerException`s when application fails to start --- .../runtime/ApplicationLifecycleManager.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 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 bc57782191e2e..33d17d3d78fe3 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java @@ -452,13 +452,15 @@ public void run() { } //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 - app.stop(); + if (app != null) { + 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 + app.stop(); + } + app.awaitShutdown(); } - app.awaitShutdown(); currentApplication = null; System.out.flush(); System.err.flush();