{"record":{"id":"f56d2999289b6caa","repo":"quarkusio/quarkus","slug":"beans","errorCode":null,"errorMessage":"${beans}","messagePattern":"\\$\\{beans\\}","errorType":"exception","errorClass":"AmbiguousResolutionException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanResolverImpl.java","lineNumber":69,"sourceCode":"        } else if (beans.size() == 1) {\n            ret = Set.of(beans.get(0));\n        } else {\n            ret = new HashSet<>(beans);\n        }\n        return ret;\n    }\n\n    @Override\n    public BeanInfo resolveAmbiguity(Set<BeanInfo> beans) {\n        if (beans == null || beans.isEmpty()) {\n            return null;\n        }\n        if (beans.size() > 1) {\n            BeanInfo selected = Beans.resolveAmbiguity(beans);\n            if (selected != null) {\n                return selected;\n            }\n            throw new AmbiguousResolutionException(beans.toString());\n        } else {\n            return beans.iterator().next();\n        }\n    }\n\n    @Override\n    public boolean matches(BeanInfo bean, TypeAndQualifiers typeAndQualifiers) {\n        return matches(bean, typeAndQualifiers.type, typeAndQualifiers.qualifiers);\n    }\n\n    @Override\n    public boolean matches(BeanInfo bean, Type requiredType, Set<AnnotationInstance> requiredQualifiers) {\n        // Bean has all the required qualifiers and a bean type that matches the required type\n        return matchesType(bean, requiredType) && Beans.hasQualifiers(bean, requiredQualifiers);\n    }\n\n    @Override\n    public boolean matchesType(BeanInfo bean, Type requiredType) {","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanResolverImpl.java#L51-L87","documentation":"This AmbiguousResolutionException is thrown during type-safe resolution when more than one bean matches an injection point and ArC's built-in disambiguation (priorities, alternatives, etc., via Beans.resolveAmbiguity) cannot select a unique bean. The message is simply the string representation of the ambiguous bean set.","triggerScenarios":"An injection point resolves to two or more beans with identical types and qualifiers, and none is an @Alternative/@Priority winner or @Singleton-defaulted; resolveAmbiguity in BeanResolverImpl is called with beans.size() > 1.","commonSituations":"Two classes implementing the same interface with the same qualifier; an @Alternative missing @Priority; duplicate producer methods producing the same type; adding a library that registers a conflicting bean.","solutions":["Add @Priority (or @Alternative + @Priority) to one of the beans to make it the default winner.","Narrow the injection point with a distinct @Qualifier.","Use @Named and inject by name, or @Default/@NonDefault qualifiers to separate the beans.","Remove or veto one of the duplicate beans (@Vetoed or exclude with profile)."],"exampleFix":"// before\n@ApplicationScoped class A implements Pay {} \n@ApplicationScoped class B implements Pay {}\n@Inject Pay pay;\n// after\n@ApplicationScoped\n@Priority(1)\n@Alternative\nclass B implements Pay {}\n// or add a qualifier\n@Qualifier @interface Fast {}","handlingStrategy":"try-catch","validationCode":"// Pre-check: count matching beans before injection\nSet<Bean<?>> matches = beanManager.getBeans(Pay.class);\nif (matches.size() > 1) {\n    System.err.println(\"Ambiguous beans for Pay: \" + matches);\n}","typeGuard":null,"tryCatchPattern":"try {\n    Pay pay = CDI.current().select(Pay.class).get();\n} catch (AmbiguousResolutionException e) {\n    // pick explicitly: CDI.current().select(Pay.class, new Fast.Literal()).get()\n}","preventionTips":["Give every injectable interface exactly one default implementation","Use @Alternative + @Priority to mark optional winners","Define and use custom qualifiers instead of relying on type alone"],"tags":["cdi","quarkus-arc","ambiguous-resolution","injection"],"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"}