{"record":{"id":"1ec6ce3c23ac76f3","repo":"quarkusio/quarkus","slug":"the-application-has-not-been-started","errorCode":null,"errorMessage":"The application has not been started","messagePattern":"The application has not been started","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/runtime/src/main/java/io/quarkus/runtime/Application.java","lineNumber":186,"sourceCode":"\n    /**\n     * Stop the application. If another thread is also trying to stop the application, this method waits for that\n     * thread to finish. Returns immediately if the application is already stopped. If an exception is thrown during\n     * stop, that exception is propagated.\n     */\n    public final void stop(Runnable afterStopTask) {\n        Logger logger = Logger.getLogger(Application.class);\n        logger.debugf(\"Stopping application\");\n        if (logger.isTraceEnabled()) {\n            logger.tracef(new RuntimeException(\"Application Stop Stack Trace\"), \"Application shutting down\");\n        }\n        final Lock stateLock = this.stateLock;\n        stateLock.lock();\n        try {\n            loop: for (;;)\n                switch (state) {\n                    case ST_INITIAL:\n                        throw new IllegalStateException(\"The application has not been started\");\n                    case ST_STARTING: {\n                        try {\n                            stateCond.await();\n                        } catch (InterruptedException e) {\n                            Thread.currentThread().interrupt();\n                            throw interruptedOnAwaitStart();\n                        }\n                        break;\n                    }\n                    case ST_STARTED:\n                        break loop; // normal shutdown\n                    case ST_STOPPING: {\n                        try {\n                            stateCond.await();\n                        } catch (InterruptedException e) {\n                            Thread.currentThread().interrupt();\n                            throw interruptedOnAwaitStop();\n                        }","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/core/runtime/src/main/java/io/quarkus/runtime/Application.java#L168-L204","documentation":"Application.stop() enforces a proper lifecycle: if stop is called while the instance is still in ST_INITIAL (never started), there is nothing to shut down and it throws this IllegalStateException. It is a misuse guard — the stop/awaitStart machinery assumes start() was invoked (or is in progress) on the instance.","triggerScenarios":"Calling app.stop() on an Application instance that was constructed but never started, or after start() failed so early that the state never advanced past ST_INITIAL — the switch case ST_INITIAL throws immediately.","commonSituations":"JUnit tests cleaning up in @AfterEach without checking whether start succeeded; error-handling paths calling stop() after a failed bootstrap; double-cleanup logic that stops unstarted instances.","solutions":["Only call stop() on instances that were successfully started; guard cleanup with a started flag or check ApplicationLifecycleManager state.","Use try/finally or the framework's lifecycle API so stop is invoked exactly once per started instance.","If start() failed, inspect and fix the startup exception first; stop() on a never-started instance is not the recovery path.","In tests, use QuarkusTest/test-extension utilities that manage lifecycle instead of manual start/stop."],"exampleFix":"// before\nApplication app = new Application();\napp.stop(); // IllegalStateException: The application has not been started\n// after\nApplication app = new Application();\nApplicationLifecycleManager.run(app, null, null, LaunchMode.NORMAL);\ntry {\n    // use app\n} finally {\n    app.stop();\n}","handlingStrategy":"validation","validationCode":"boolean started = app.isStarted(); // or track your own flag set after start() returns\nif (!started) {\n    throw new IllegalStateException(\"Cannot stop: application was never started\");\n}","typeGuard":"boolean canStop(Application app) {\n    try {\n        java.lang.reflect.Field f = Application.class.getDeclaredField(\"state\");\n        f.setAccessible(true);\n        return ((AtomicInteger) f.get(app)).get() != 0; // != ST_INITIAL\n    } catch (ReflectiveOperationException e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    app.stop();\n} catch (IllegalStateException e) {\n    if (\"The application has not been started\".equals(e.getMessage())) {\n        log.debug(\"stop() skipped: never started\");\n    } else throw e;\n}","preventionTips":["Pair every start() with exactly one stop() in try/finally.","Set a boolean started flag after successful start and check it in cleanup code.","In JUnit cleanup, skip stop() when startup failed.","Prefer @QuarkusTest lifecycle management over manual Application instances."],"tags":["quarkus","lifecycle","shutdown","state-machine"],"backgroundTag":"application-not-started","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}