{"record":{"id":"69537cbcacd57677","repo":"quarkusio/quarkus","slug":"cdi-bean-s-is-not-available-but-it-is-required","errorCode":null,"errorMessage":"CDI bean '%s' is not available, but it is required by the @PermissionChecker method","messagePattern":"CDI bean '(.+?)' is not available, but it is required by the @PermissionChecker method","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/security/runtime/src/main/java/io/quarkus/security/runtime/QuarkusPermission.java","lineNumber":128,"sourceCode":"        return \"\";\n    }\n\n    @Override\n    public final boolean equals(Object object) {\n        return this == object;\n    }\n\n    @Override\n    public final int hashCode() {\n        return Objects.hash(toString());\n    }\n\n    private InstanceHandle<T> getBeanInstanceHandle() {\n        if (bean == null) {\n            // this is done lazily because permissions without extra constructor arguments are created before Arc is ready\n            bean = Arc.container().instance(getBeanClass());\n            if (!bean.isAvailable()) {\n                throw new IllegalStateException(\n                        \"CDI bean '%s' is not available, but it is required by the @PermissionChecker method\"\n                                .formatted(getBeanClass()));\n            }\n        }\n        return bean;\n    }\n\n    // used by generated subclasses\n    protected static Uni<Boolean> accessDenied() {\n        return Uni.createFrom().item(false);\n    }\n}\n","sourceCodeStart":110,"sourceCodeEnd":141,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/security/runtime/src/main/java/io/quarkus/security/runtime/QuarkusPermission.java#L110-L141","documentation":"PermissionChecker beans referenced by @PermissionChecker-generated QuarkusPermission instances are looked up lazily through Arc at authorization time. If the CDI bean cannot be resolved (bean not discovered or not registered), getBeanInstanceHandle throws IllegalStateException naming the bean class.","triggerScenarios":"At authorization time, the bean class backing a @PermissionChecker method is not an available CDI bean: missing @ApplicationScoped or other bean-defining annotation, wrong package excluded by quarkus.arc exclude, or the class was moved/refactored.","commonSituations":"Forgetting a bean-defining annotation on the class containing the @PermissionChecker method; beans-only build (quarkus.arc.legacy-... off) skipping unannotated classes; tests where the bean package is not scanned.","solutions":["Annotate the class owning the @PermissionChecker method with a bean-defining annotation (@ApplicationScoped or @Singleton).","Verify the bean is not excluded by quarkus.arc.exclude-packages / quarkus.index-dependencies scoping and that the package is indexed.","Run with quarkus.arc.fail-non-init or inspect the build log for bean discovery warnings; confirm Arc.container().instance(MyBean.class).isAvailable() is true."],"exampleFix":"// before\npublic class UserPermissionChecker {\n    @PermissionChecker(\"delete:user\")\n    boolean canDelete(...) { ... }\n}\n// after\n@ApplicationScoped\npublic class UserPermissionChecker {\n    @PermissionChecker(\"delete:user\")\n    boolean canDelete(...) { ... }\n}","handlingStrategy":"validation","validationCode":"// startup sanity check\nInstanceHandle<MyBean> h = Arc.container().instance(MyBean.class);\nif (!h.isAvailable()) throw new IllegalStateException(\"MyBean not discovered: add a bean-defining annotation\");","typeGuard":null,"tryCatchPattern":"try {\n    boolean ok = permissionChecker.check(auth);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"is not available\")) {\n        // bean discovery issue: log and fail deployment in dev\n    } else throw e;\n}","preventionTips":["Annotate permission-checker classes with @ApplicationScoped","Keep beans in indexed packages","Run a startup Arc availability test in CI"],"tags":["quarkus","security","cdi","bean-discovery"],"backgroundTag":"cdi-bean-not-found","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}