quarkusio/quarkus · error · IllegalStateException

Invalid `codec` argument in @ConsumeEvent - no parameter

Error message

Invalid `codec` argument in @ConsumeEvent - no parameter

What it means

When @ConsumeEvent(codec = SomeCodec.class) is used, the consumer method must have at least one parameter that identifies the payload type the codec applies to. If the method has no parameter to infer a payload type from, the build fails with this IllegalStateException.

Source

Thrown at extensions/vertx/deployment/src/main/java/io/quarkus/vertx/deployment/EventBusCodecProcessor.java:73

        final IndexView index = beanArchiveIndexBuildItem.getIndex();
        Collection<AnnotationInstance> consumeEventAnnotationInstances = index.getAnnotations(CONSUME_EVENT);
        Map<DotName, DotName> codecByTypes = new HashMap<>();
        Set<DotName> selectorTypes = new HashSet<>();

        for (AnnotationInstance consumeEventAnnotationInstance : consumeEventAnnotationInstances) {
            AnnotationTarget typeTarget = consumeEventAnnotationInstance.target();
            if (typeTarget.kind() != AnnotationTarget.Kind.METHOD) {
                throw new IllegalStateException("@ConsumeEvent annotation must target a method");
            }
            MethodInfo method = typeTarget.asMethod();

            Type codecTargetFromParameter = extractPayloadTypeFromParameter(method);
            // If the @ConsumeEvent set the codec, use this codec. It applies to the parameter
            AnnotationValue codec = consumeEventAnnotationInstance.value("codec");
            if (codec != null && codec.asClass().kind() == Type.Kind.CLASS) {
                if (codecTargetFromParameter == null) {
                    throw new IllegalStateException("Invalid `codec` argument in @ConsumeEvent - no parameter");
                }
                codecByTypes.put(codecTargetFromParameter.name(), codec.asClass().asClassType().name());
            } else if (codecTargetFromParameter != null && !hasBuiltInCodec(codecTargetFromParameter)) {
                // Codec is not set and built-in codecs cannot be used
                if (!codecByTypes.containsKey(codecTargetFromParameter.name())) {
                    if (isConcreteClass(codecTargetFromParameter, index)) {
                        // The default codec makes only sense for concrete classes
                        LOGGER.debugf("Local Message Codec registered for type %s",
                                codecTargetFromParameter);
                        codecByTypes.put(codecTargetFromParameter.name(), LOCAL_EVENT_BUS_CODEC);
                    } else {
                        LOGGER.debugf("Local Message Codec will be selected for type %s", codecTargetFromParameter);
                        selectorTypes.add(codecTargetFromParameter.name());
                    }
                }
            }

            Type codecTargetFromReturnType = extractPayloadTypeFromReturn(method);

View on GitHub (pinned to e1c734241f)

Solutions

  1. Give the consumer method a parameter matching the codec's payload type
  2. Remove the codec attribute if the method intentionally consumes no payload
  3. Use the Message<T> parameter form so the payload type is explicit

Example fix

// before
@ConsumeEvent(value = "addr", codec = MyCodec.class)
public void onEvent() { }
// after
@ConsumeEvent(value = "addr", codec = MyCodec.class)
public void onEvent(MyPayload payload) { }
Defensive patterns

Strategy: validation

Validate before calling

// codec consumers must have a payload parameter
Method m = MyConsumer.class.getDeclaredMethod("on");
if (m.isAnnotationPresent(ConsumeEvent.class)
    && m.getAnnotation(ConsumeEvent.class).codec() != Object.class
    && m.getParameterCount() == 0) {
    throw new IllegalStateException("codec requires a payload parameter");
}

Prevention

When it happens

Trigger: Annotating a codec-bearing @ConsumeEvent on a zero-parameter method; a method whose parameters are all unannotated primitives/generics that yield no payload type.

Common situations: Refactoring a consumer to take no argument while keeping the codec; typo making the payload type invisible to the annotation processor (raw generic parameter).

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/f39b92a1cb27897e. Report an issue: GitHub.