{"record":{"id":"02b61b29dabe24dc","repo":"quarkusio/quarkus","slug":"injected-field-cannot-be-annotated-with-produces","errorCode":null,"errorMessage":"Injected field cannot be annotated with @Produces: ${field}","messagePattern":"Injected field cannot be annotated with @Produces: (.+?)","errorType":"exception","errorClass":"DefinitionException","httpStatus":null,"severity":"error","filePath":"independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanDeployment.java","lineNumber":1305,"sourceCode":"                                            \"Observer method found but %s has no bean defining annotation - using @Dependent\",\n                                            beanClass);\n                                }\n                            }\n                        }\n                    }\n                }\n                DotName superType = aClass.superName();\n                aClass = superType != null && !superType.equals(DotNames.OBJECT)\n                        ? getClassByName(getBeanArchiveIndex(), superType)\n                        : null;\n            }\n\n            // non-inherited fields\n            for (FieldInfo field : beanClass.fields()) {\n                if (annotationStore.hasAnnotation(field, DotNames.PRODUCES)\n                        && !annotationStore.hasAnnotation(field, DotNames.VETOED_PRODUCER)) {\n                    if (annotationStore.hasAnnotation(field, DotNames.INJECT)) {\n                        throw new DefinitionException(\"Injected field cannot be annotated with @Produces: \" + field);\n                    }\n                    // Do not register classes with producers and no bean def. annotation as beans in strict mode\n                    // Producer fields are not inherited\n                    if (strictCompatibility) {\n                        if (hasBeanDefiningAnnotation) {\n                            producerFields.add(field);\n                        }\n                    } else {\n                        producerFields.add(field);\n                        if (!hasBeanDefiningAnnotation) {\n                            LOGGER.debugf(\"Producer field found but %s has no bean defining annotation - using @Dependent\",\n                                    beanClass);\n                            beanClasses.add(beanClass);\n                        }\n                    }\n                } else if (!annotationStore.hasAnnotation(field, DotNames.PRODUCES)) {\n                    // Verify that non-producer fields are not annotated with stereotypes\n                    // (vetoed producers must _not_ be checked)","sourceCodeStart":1287,"sourceCodeEnd":1323,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanDeployment.java#L1287-L1323","documentation":"A field annotated @Inject (an injected field, i.e. managed by the container) cannot also be annotated @Produces. Producer fields must not be injection targets; ArC throws this DefinitionException during field scanning of the bean class.","triggerScenarios":"A field has both @Inject and @Produces annotations (and is not a @VetoedProducer); BeanDeployment.deploy iterates beanClass.fields() and detects the combination.","commonSituations":"Converting an injected field into a producer by adding @Produces without removing @Inject; copy-paste of annotation blocks; IDE quick-fixes stacking annotations.","solutions":["Remove @Inject from the producer field and inject the needed dependencies elsewhere (e.g. constructor).","If you actually want injection, remove @Produces instead.","If the field must keep both for compatibility but should not be registered, mark it @VetoedProducer (or @Vetoed) to skip producer registration."],"exampleFix":"// before\n@Inject\n@Produces\nConfig config;\n// after\n@Produces\nConfig config; // dependencies injected via constructor instead","handlingStrategy":"validation","validationCode":"if (field.isAnnotationPresent(Inject.class) && field.isAnnotationPresent(Produces.class)) {\n    throw new IllegalStateException(\"@Inject and @Produces cannot both be on \" + field);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never combine @Inject and @Produces on the same field","Inject dependencies via constructor when writing producers","Search codebase for fields carrying both annotations in review checklist"],"tags":["cdi","quarkus-arc","producer-field","inject"],"backgroundTag":"produces-with-inject-conflict","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"}