{"record":{"id":"63baee10cb547db4","repo":"quarkusio/quarkus","slug":"more-than-one-active-bean-found-list","errorCode":null,"errorMessage":"More than one active bean found: \" + list","messagePattern":"More than one active bean found: \" \\+ list","errorType":"exception","errorClass":"AmbiguousResolutionException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/runtime/src/main/java/io/quarkus/arc/InjectableInstance.java","lineNumber":101,"sourceCode":"    default T orNull() {\n        return orElse(null);\n    }\n\n    /**\n     * Returns exactly one instance of an {@linkplain InjectableBean#checkActive() active} bean that matches\n     * the required type and qualifiers. If no active bean matches, or if more than one active bean matches,\n     * throws an exception.\n     *\n     * @return the single instance of an active matching bean\n     */\n    default T getActive() {\n        List<T> list = listActive();\n        if (list.size() == 1) {\n            return list.get(0);\n        } else if (list.isEmpty()) {\n            throw new UnsatisfiedResolutionException(\"No active bean found\");\n        } else {\n            throw new AmbiguousResolutionException(\"More than one active bean found: \" + list);\n        }\n    }\n\n    /**\n     * Returns the list of instances of {@linkplain InjectableBean#checkActive() active} beans that match\n     * the required type and qualifiers, sorter in priority order (higher priority goes first).\n     *\n     * @return the list of instances of matching active beans\n     */\n    default List<T> listActive() {\n        return handlesStream().filter(it -> it.getBean().isActive()).map(InstanceHandle::get).toList();\n    }\n}\n","sourceCodeStart":83,"sourceCodeEnd":115,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/InjectableInstance.java#L83-L115","documentation":"Thrown by InjectableInstance.getActive() when more than one bean matches the required type and qualifiers and is active. getActive() is a convenience for unambiguous resolution, so CDI's ambiguity rule makes multiple candidates fatal. The exception message lists all conflicting beans.","triggerScenarios":"Calling Instance<Foo>.getActive() (or getHandler().get()) when listActive() returns more than one active bean — i.e. two or more beans of the same type (and qualifiers) exist, e.g. via @Alternative mishandling, duplicate @Priority, or accidentally adding a second bean class.","commonSituations":"Adding a second implementation of an interface without distinguishing qualifiers; forgetting to enable an @Alternative with @Priority so both implementations match; a library and app both exposing the same bean; tests where a mock bean was registered alongside the real one.","solutions":["Add a qualifier annotation to distinguish the beans and inject with that qualifier","Use @Alternative + @Priority (or quarkus.arc.select-alternatives) so only one candidate is active for the injection point","Replace getActive() with select(qualifier).get() to narrow the selection programmatically","Remove or exclude the duplicate bean (e.g. via @Exclude or removing the @Produces/@ApplicationScoped)","Inspect the exception message list to identify the conflicting bean classes"],"exampleFix":"// before\nPaymentService svc = instance.getActive(); // AmbiguousResolutionException\n// after\n@Priority(1) @Alternative @ApplicationScoped\nclass MockPaymentService implements PaymentService { }\n// or narrow:\nPaymentService svc = instance.select(MockPaymentService.Literal.INSTANCE).get();","handlingStrategy":"validation","validationCode":"List<PaymentService> all = instance.select(PaymentService.class).handlesStream().map(Instance.Handle::get).toList();\nif (all.size() != 1) throw new IllegalStateException(\"Expected exactly 1 PaymentService bean, found: \" + all.size());","typeGuard":"if (instance.isAmbiguous()) { /* narrow with qualifier or alternative */ }","tryCatchPattern":"try { svc = instance.getActive(); } catch (AmbiguousResolutionException e) { log.errorf(\"Ambiguous beans: %s\", e.getMessage()); svc = instance.select(Default.Literal.INSTANCE).get(); }","preventionTips":["Give each bean a distinct qualifier when multiple implementations exist","Mark test/duplicate beans @Alternative with @Priority","Run Arc container startup checks early (fail-fast at boot, not first injection)"],"tags":["cdi","ambiguity","dependency-injection"],"backgroundTag":"ambiguous-cdi-bean-resolution","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"}