{"record":{"id":"fff97c13a5a8b245","repo":"quarkusio/quarkus","slug":"producer-method-must-not-be-annotated-inject-alt","errorCode":null,"errorMessage":"Producer method must not be annotated @Inject (alternatively, initializer method must not be annotated @Produces): ","messagePattern":"Producer method must not be annotated @Inject \\(alternatively, initializer method must not be annotated @Produces\\): ","errorType":"validation","errorClass":"DefinitionException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java","lineNumber":277,"sourceCode":"                }\n                if (Annotations.hasParameterAnnotation(beanDeployment, initializerMethod, DotNames.OBSERVES)) {\n                    throw new DefinitionException(\"Initializer method must not have an @Observes parameter \"\n                            + \"(alternatively, observer method must not be annotated @Inject): \"\n                            + beanTarget.asClass() + \".\" + initializerMethod.name());\n                }\n                if (Annotations.hasParameterAnnotation(beanDeployment, initializerMethod, DotNames.OBSERVES_ASYNC)) {\n                    throw new DefinitionException(\"Initializer method must not have an @ObservesAsync parameter \"\n                            + \"(alternatively, async observer method must not be annotated @Inject): \"\n                            + beanTarget.asClass() + \".\" + initializerMethod.name());\n                }\n            }\n            validateInjections(injections, beanType);\n            return injections;\n        } else if (Kind.METHOD.equals(beanTarget.kind())) {\n            MethodInfo producerMethod = beanTarget.asMethod();\n\n            if (beanDeployment.hasAnnotation(producerMethod, DotNames.INJECT)) {\n                throw new DefinitionException(\"Producer method must not be annotated @Inject \"\n                        + \"(alternatively, initializer method must not be annotated @Produces): \"\n                        + producerMethod);\n            }\n            if (Annotations.hasParameterAnnotation(beanDeployment, producerMethod, DotNames.DISPOSES)) {\n                throw new DefinitionException(\"Producer method must not have a @Disposes parameter \"\n                        + \"(alternatively, disposer method must not be annotated @Produces): \"\n                        + producerMethod);\n            }\n            if (Annotations.hasParameterAnnotation(beanDeployment, producerMethod, DotNames.OBSERVES)) {\n                throw new DefinitionException(\"Producer method must not have an @Observes parameter \"\n                        + \"(alternatively, observer method must not be annotated @Produces): \"\n                        + producerMethod);\n            }\n            if (Annotations.hasParameterAnnotation(beanDeployment, producerMethod, DotNames.OBSERVES_ASYNC)) {\n                throw new DefinitionException(\"Producer method must not have an @ObservesAsync parameter \"\n                        + \"(alternatively, async observer method must not be annotated @Produces): \"\n                        + producerMethod);\n            }","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java#L259-L295","documentation":"ArC throws this DefinitionException when a producer method (@Produces) is also annotated @Inject — the mirror case of error 2763. A method cannot be both a producer and an injection target; when beanTarget.kind() is METHOD, forBean checks the producer method for DotNames.INJECT and rejects the definition.","triggerScenarios":"Annotating a @Produces method with @Inject in a bean class; detected in forBean's METHOD branch via beanDeployment.hasAnnotation(producerMethod, DotNames.INJECT).","commonSituations":"IDE quick-fixes adding @Inject alongside @Produces; assuming producer methods need @Inject to participate in injection; code merged from two sources each adding one annotation.","solutions":["Remove @Inject from the producer method, keeping @Produces","If the method was meant as an initializer, remove @Produces instead and keep @Inject with void return semantics","Ensure the class containing the producer is itself a bean (@ApplicationScoped etc.) if you expected it to be injectable","Rebuild; error is raised during augmentation"],"exampleFix":"// before\n@Inject\n@Produces\nConfig config() { return loadConfig(); }\n\n// after\n@Produces\nConfig config() { return loadConfig(); }","handlingStrategy":"validation","validationCode":"void checkMethod(Method m) {\n    boolean inject = m.isAnnotationPresent(jakarta.inject.Inject.class);\n    boolean produces = m.isAnnotationPresent(jakarta.enterprise.inject.Produces.class);\n    if (inject && produces) {\n        throw new IllegalStateException(\"@Inject + @Produces on: \" + m);\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Producer methods never need @Inject — discovery is via @Produces","Do not accept IDE suggestions adding @Inject to producers","Ensure the hosting bean class is properly scoped (@ApplicationScoped, etc.)","Review annotation pairs in merged code"],"tags":["cdi","arc","produces","inject","producer","bean-definition","build-time"],"backgroundTag":"cdi-bean-definition-invalid","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}