{"record":{"id":"f8a7042ff487dea3","repo":"quarkusio/quarkus","slug":"multiple-inject-constructors-found-on","errorCode":null,"errorMessage":"Multiple @Inject constructors found on ","messagePattern":"Multiple @Inject constructors found on ","errorType":"validation","errorClass":"DefinitionException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java","lineNumber":221,"sourceCode":"\n    private static void validateInjections(List<Injection> injections, BeanType beanType) {\n        for (Injection injection : injections) {\n            for (InjectionPointInfo ipi : injection.injectionPoints) {\n                validateInjections(ipi, beanType);\n            }\n        }\n    }\n\n    static List<Injection> forBean(AnnotationTarget beanTarget, BeanInfo declaringBean, BeanDeployment beanDeployment,\n            InjectionPointModifier transformer, BeanType beanType) {\n        if (Kind.CLASS.equals(beanTarget.kind())) {\n            List<Injection> injections = forClassBean(beanTarget.asClass(), beanTarget.asClass(), beanDeployment,\n                    transformer, false, new HashSet<>());\n\n            Set<AnnotationTarget> injectConstructors = injections.stream().filter(Injection::isConstructor)\n                    .map(Injection::getTarget).collect(Collectors.toSet());\n            if (injectConstructors.size() > 1) {\n                throw new DefinitionException(\n                        \"Multiple @Inject constructors found on \" + beanTarget.asClass().name() + \":\\n\"\n                                + injectConstructors.stream().map(Object::toString).collect(Collectors.joining(\"\\n\")));\n            }\n            for (AnnotationTarget injectConstructor : injectConstructors) {\n                Set<AnnotationInstance> parameterAnnotations = Annotations.getParameterAnnotations(beanDeployment,\n                        injectConstructor.asMethod());\n                for (AnnotationInstance annotation : parameterAnnotations) {\n                    if (DotNames.DISPOSES.equals(annotation.name())) {\n                        throw new DefinitionException(\n                                \"Bean constructor must not have a @Disposes parameter: \" + injectConstructor);\n                    }\n                    if (DotNames.OBSERVES.equals(annotation.name())) {\n                        throw new DefinitionException(\n                                \"Bean constructor must not have an @Observes parameter: \" + injectConstructor);\n                    }\n                    if (DotNames.OBSERVES_ASYNC.equals(annotation.name())) {\n                        throw new DefinitionException(\n                                \"Bean constructor must not have an @ObservesAsync parameter: \" + injectConstructor);","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java#L203-L239","documentation":"A CDI bean class may declare at most one constructor annotated @Inject (the bean constructor). ArC counts @Inject-annotated constructors during bean processing and throws this DefinitionException (listing all of them) when a bean class has more than one.","triggerScenarios":"Annotating two or more constructors of a bean class with @Inject, e.g. after adding a new constructor with dependencies while leaving @Inject on the old no-arg constructor.","commonSituations":"Refactoring that adds a constructor for testing while keeping the old @Inject constructor; merge conflicts keeping duplicate constructors; not realizing only one constructor may carry @Inject.","solutions":["Remove @Inject from all but one constructor; ArC will pick the single annotated one","If the class has exactly one constructor, remove @Inject entirely — it is used automatically","Make the no-arg constructor package-private or remove it if it was only there for frameworks"],"exampleFix":"// before\nclass MyBean { @Inject MyBean() {} @Inject MyBean(Other o) {} }\n// after\nclass MyBean { @Inject MyBean(Other o) {} }","handlingStrategy":"validation","validationCode":"long n = java.util.Arrays.stream(MyBean.class.getDeclaredConstructors())\n    .filter(c -> c.isAnnotationPresent(jakarta.inject.Inject.class)).count();\nif (n > 1) throw new IllegalStateException(\"At most one @Inject constructor allowed on MyBean\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["At most one @Inject constructor per bean class","Single-constructor classes need no @Inject at all","Remove legacy constructors or their @Inject annotations when adding new ones"],"tags":["cdi","arc","constructor-injection","build-time"],"backgroundTag":"cdi-definition-error","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"}