{"record":{"id":"05ccd1f188bdeeda","repo":"quarkusio/quarkus","slug":"producer-method-must-not-have-a-disposes-paramete","errorCode":null,"errorMessage":"Producer method must not have a @Disposes parameter (alternatively, disposer method must not be annotated @Produces): ","messagePattern":"Producer method must not have a @Disposes parameter \\(alternatively, disposer 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":282,"sourceCode":"                }\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            }\n\n            if (producerMethod.parameterTypes().isEmpty()) {\n                return Collections.emptyList();\n            }\n            // All parameters are injection points","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java#L264-L300","documentation":"ArC throws this DefinitionException when a producer method has a parameter annotated @Disposes, or a disposer method is annotated @Produces. Producer methods take only plain injection parameters; disposal belongs on a separate @Disposes method that consumes the produced object. forBean's METHOD branch checks producer parameters for DISPOSES.","triggerScenarios":"Declaring @Produces Resource produce(@Disposes Resource r); detected by Annotations.hasParameterAnnotation(producerMethod, DotNames.DISPOSES) in forBean.","commonSituations":"Trying to define production and disposal in one method; copy-pasting a disposer signature into the producer; misunderstanding the producer/disposer pairing model in CDI.","solutions":["Remove @Disposes from the producer method parameter","Add a separate disposer method in the same bean: void dispose(@Disposes Resource r) { r.close(); }","Verify the disposer is in the same class (or a dependent bean) as the producer so ArC can pair them","Rebuild; check runs at augmentation time"],"exampleFix":"// before\n@Produces\nResource produce(@Disposes Config cfg) { return new Resource(cfg); }\n\n// after\n@Produces\nResource produce(Config cfg) { return new Resource(cfg); }\n\nvoid dispose(@Disposes Resource r) { r.close(); }","handlingStrategy":"validation","validationCode":"void checkProducer(Method m) {\n    if (!m.isAnnotationPresent(jakarta.enterprise.inject.Produces.class)) return;\n    for (var p : m.getParameters()) {\n        if (p.isAnnotationPresent(jakarta.enterprise.inject.Disposes.class)) {\n            throw new IllegalStateException(\"@Disposes on producer param: \" + m);\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always define disposal in a separate @Disposes method, never on the producer","Keep producer parameters as plain injection points","Place the disposer in the same class as the producer so ArC pairs them","Search for '@Disposes' placement during code review"],"tags":["cdi","arc","disposes","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"}