{"record":{"id":"d8c6671358817d54","repo":"quarkusio/quarkus","slug":"beans-d8c667","errorCode":null,"errorMessage":"Beans: ","messagePattern":"Beans: ","errorType":"exception","errorClass":"AmbiguousResolutionException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/InstanceImpl.java","lineNumber":291,"sourceCode":"                    if (resetCurrentInjectionPoint) {\n                        InjectionPointProvider.setCurrent(context, prev);\n                    }\n                }\n            }\n        },\n                // If @Dependent we need to remove the instance from the CC of this InjectableInstance\n                Dependent.class.equals(bean.getScope()) ? this::destroy : null);\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    private InjectableBean<T> bean() {\n        List<InjectableBean<?>> beans = beans();\n        if (beans.isEmpty()) {\n            ArcContainerImpl.instance().scanRemovedBeans(requiredType, requiredQualifiers.toArray(new Annotation[] {}));\n            throw new UnsatisfiedResolutionException(\n                    \"No bean found for required type [\" + requiredType + \"] and qualifiers [\" + requiredQualifiers + \"]\");\n        } else if (beans.size() > 1) {\n            throw new AmbiguousResolutionException(\"Beans: \" + beans.toString());\n        }\n        return (InjectableBean<T>) beans.iterator().next();\n    }\n\n    public boolean hasDependentInstances() {\n        return creationalContext.hasDependentInstances();\n    }\n\n    @Override\n    public void clearCache() {\n        if (cachedGetResult.isSet()) {\n            creationalContext.release();\n            cachedGetResult.clear();\n        }\n    }\n\n    private T getInternal() {\n        return getBeanInstance(bean());","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/InstanceImpl.java#L273-L309","documentation":"When Instance resolution finds more than one bean matching the required type and qualifiers, ArC throws AmbiguousResolutionException('Beans: ' + list). The message enumerates the ambiguous beans so you can see exactly which candidates conflict.","triggerScenarios":"Calling instance.get()/getHandle() after select() where two or more beans match the type and qualifiers — e.g. two implementations of the same interface with the same/default qualifiers.","commonSituations":"Adding a second implementation of an interface used elsewhere with default qualifiers; a library upgrade introduces a bean that duplicates an app bean; forgotten @Alternative/@Default differentiation.","solutions":["Add a distinguishing qualifier annotation to each implementation and select with it","Mark one implementation @Alternative (and activate it in application.properties) or @Default/@Priority","Narrow the select() call with additional qualifiers so only one bean matches","If one bean should never be used, make it @Vetoed or remove it"],"exampleFix":"// before\ninstance.select(PaymentService.class).get(); // 2 impls -> ambiguous\n// after\n@Qualifier @Retention(RUNTIME) @interface Stripe {}\ninstance.select(PaymentService.class, new Stripe.Literal()).get();","handlingStrategy":"validation","validationCode":"Instance<PaymentService> candidates = instance.select(PaymentService.class, qualifier);\nif (candidates.isAmbiguous()) {\n    throw new IllegalStateException(\"Multiple beans for PaymentService: add a qualifier or @Alternative\");\n}","typeGuard":"static <T> T unique(Instance<T> i) {\n    if (i.isAmbiguous()) throw new IllegalStateException(\"Ambiguous: \" + i.stream().map(b -> b.getBean().getBeanClass()).toList());\n    if (i.isUnsatisfied()) throw new IllegalStateException(\"Unsatisfied\");\n    return i.get();\n}","tryCatchPattern":"try {\n    svc = instance.select(PaymentService.class).get();\n} catch (AmbiguousResolutionException e) {\n    log.errorf(\"Ambiguous beans: %s — add qualifier/Alternative\", e.getMessage());\n    throw e;\n}","preventionTips":["Give every multi-implementation interface a qualifier per implementation","Run a startup smoke test — ambiguous resolution fails fast at first lookup","Use @Default and @Alternative deliberately; audit them when adding new implementations","Check Instance.isAmbiguous() before get()"],"tags":["cdi","arc","dependency-injection","ambiguous-resolution"],"backgroundTag":"ambiguous-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"}