{"record":{"id":"c5c6324ccce352bc","repo":"quarkusio/quarkus","slug":"invalid-state-state-getclass-getname","errorCode":null,"errorMessage":"Invalid state: \" + state.getClass().getName()","messagePattern":"Invalid state: \" \\+ state\\.getClass\\(\\)\\.getName\\(\\)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/AbstractSharedContext.java","lineNumber":133,"sourceCode":"                    instanceHandle.destroy();\n                }\n            });\n        }\n        instances.removeEach(null);\n    }\n\n    private ArcShutdownAction actionType(InjectableBean<?> bean) {\n        return bean.getScope().equals(ApplicationScoped.class)\n                ? ArcShutdownAction.CDI_DESTROY_APPLICATION_BEAN\n                : ArcShutdownAction.CDI_DESTROY_SINGLETON_BEAN;\n    }\n\n    @Override\n    public void destroy(ContextState state) {\n        if (state == this) {\n            destroy();\n        } else {\n            throw new IllegalArgumentException(\"Invalid state: \" + state.getClass().getName());\n        }\n    }\n\n    @SuppressWarnings({ \"unchecked\", \"rawtypes\" })\n    private static <T> ContextInstanceHandle createInstanceHandle(InjectableBean<T> bean,\n            CreationalContext<T> creationalContext) {\n        return new ContextInstanceHandleImpl(bean, bean.create(creationalContext), creationalContext);\n    }\n\n}\n","sourceCodeStart":115,"sourceCodeEnd":144,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/AbstractSharedContext.java#L115-L144","documentation":"AbstractSharedContext.destroy(ContextState) throws IllegalArgumentException when the given state is not the context itself. A shared context only accepts destroying its own state (self-destruction) or states it owns; a foreign ContextState indicates a programming error by the caller.","triggerScenarios":"Calling context.destroy(someState) with a ContextState obtained from a different context instance (e.g. two @ApplicationScoped contexts, or a state from a mock/custom context).","commonSituations":"Custom context implementations mismanaging state ownership; tests reusing ContextState across container restarts; multiple containers (dev mode restarts) mixing stale states with fresh contexts.","solutions":["Call context.destroy() (no args) to destroy the context's current state instead of passing an external state","Only pass ContextState values obtained from this same context instance","Guard with context.getState() == state before calling destroy(state)","Re-create the handle/context pair if states were obtained from a previous container instance"],"exampleFix":"// before\nappContext.destroy(someOtherState); // IllegalArgumentException\n// after\nif (appContext.getState() == someState) {\n    appContext.destroy(someState);\n} else {\n    appContext.destroy();\n}","handlingStrategy":"type-guard","validationCode":"if (ctx.getState() != state) { ctx.destroy(); return; }","typeGuard":"boolean owned = state != null && ctx.getState() == state;","tryCatchPattern":"try { ctx.destroy(state); } catch (IllegalArgumentException e) { ctx.destroy(); }","preventionTips":["Only destroy states obtained from the same context instance","Prefer no-arg destroy() for whole-context teardown","Avoid sharing ContextState across container restarts"],"tags":["cdi","context","state"],"backgroundTag":"invalid-context-state","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}