quarkusio/quarkus · error · DefinitionException
An interceptor field cannot be marked @Produces -
Error message
An interceptor field cannot be marked @Produces -
What it means
ArC throws this DefinitionException when a field of an interceptor class (or any superclass in the hierarchy walk) is annotated with @Produces. Per the CDI specification, interceptor classes must not declare producer fields, so this invalid interceptor definition is rejected during build-time bean discovery and the application fails to start.
Source
Thrown at independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/InterceptorInfo.java:152
throw new DefinitionException(
"Multiple @PostConstruct interceptor methods declared on class: " + aClass);
}
}
if (store.hasAnnotation(method, DotNames.PRE_DESTROY)) {
addInterceptorMethod(allMethods, preDestroys, method, InterceptionType.PRE_DESTROY,
InterceptorPlacement.INTERCEPTOR_CLASS);
if (++preDestroysFound > 1) {
throw new DefinitionException(
"Multiple @PreDestroy interceptor methods declared on class: " + aClass);
}
}
allMethods.add(method);
}
for (FieldInfo field : aClass.fields()) {
if (store.hasAnnotation(field, DotNames.PRODUCES)) {
// according to spec, finding @Produces on a field is a DefinitionException
throw new DefinitionException(
"An interceptor field cannot be marked @Produces - " + field + " in class: " + aClass);
}
}
DotName superTypeName = aClass.superName();
aClass = superTypeName == null || DotNames.OBJECT.equals(superTypeName) ? null
: getClassByName(beanDeployment.getBeanArchiveIndex(), superTypeName);
}
// The interceptor methods defined by the superclasses are invoked before the interceptor method defined by the interceptor class, most general superclass first.
Collections.reverse(aroundInvokes);
Collections.reverse(postConstructs);
Collections.reverse(preDestroys);
Collections.reverse(aroundConstructs);
this.aroundInvokes = List.copyOf(aroundInvokes);
this.aroundConstructs = List.copyOf(aroundConstructs);
this.postConstructs = List.copyOf(postConstructs);View on GitHub (pinned to e1c734241f)
Solutions
- Remove the @Produces annotation from the field; interceptors get dependencies via @Inject constructor/field injection only.
- Move the producer field to a regular CDI bean (e.g. an @ApplicationScoped class) if a producer is genuinely needed.
- If the interceptor needs the produced value, @Inject the bean produced elsewhere instead of producing it inside the interceptor.
Example fix
// before
@Interceptor @Audited
class AuditInterceptor {
@Produces
@Named("auditMode")
String auditMode = "strict";
}
// after
@Interceptor @Audited
class AuditInterceptor {
@Inject
AuditConfig config; // inject instead of producing
} Defensive patterns
Strategy: validation
Validate before calling
for (java.lang.reflect.Field f : AuditInterceptor.class.getFields()) {
if (f.isAnnotationPresent(javax.enterprise.inject.Produces.class)
|| f.isAnnotationPresent(jakarta.enterprise.inject.Produces.class)) {
throw new IllegalStateException("@Produces not allowed on interceptor fields: " + f);
}
} Prevention
- Never annotate fields in @Interceptor classes with @Produces; use @Inject for dependencies
- Move producers to dedicated @ApplicationScoped producer beans
- Search for @Produces in interceptor packages as a pre-build sanity check
When it happens
Trigger: Annotating any field in a class used as an @Interceptor (or in its superclass) with @Produces — e.g. trying to expose a produced bean from inside an interceptor.
Common situations: Copy-pasting a producer field into an interceptor class; moving a @Produces field into an interceptor during refactoring; confusion between interceptor classes and regular beans.
Related errors
- Interceptor declares a producer method:
- An interceptor method cannot be marked @Produces or @Dispose
- Multiple @AroundInvoke interceptor methods declared on class
- Multiple @AroundConstruct interceptor methods declared on cl
- Multiple @PostConstruct interceptor methods declared on clas
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/54a16945c9f4daa2.
Report an issue: GitHub.