quarkusio/quarkus · error · RuntimeException

Method '${targetMethod.name()} of class '${targetMethod.decl

Error message

Method '${targetMethod.name()} of class '${targetMethod.declaringClass().name()}' cannot be used as a response filter as it does not declare 'void' or 'Uni<Void>' as its return type

What it means

A @ServerResponseFilter method must return void or Uni<Void>. Unlike request filters, response filters cannot abort with a Response object, so any other return type is rejected by determineResponseFilterReturnType during augmentation.

Source

Thrown at independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/generation/filters/CustomFilterGenerator.java:756

        } else if (targetMethod.returnType().name().equals(RESPONSE)) {
            return ReturnType.RESPONSE;
        }
        throw new RuntimeException("Method '" + targetMethod.name() + " of class '" + targetMethod.declaringClass().name()
                + "' cannot be used as a request filter as it does not declare 'void', Response, RestResponse, Optional<Response>, Optional<RestResponse>, 'Uni<Void>', 'Uni<RestResponse>' or 'Uni<Response>' as its return type");
    }

    private ReturnType determineResponseFilterReturnType(MethodInfo targetMethod) {
        if (targetMethod.returnType().kind() == Type.Kind.VOID) {
            return ReturnType.VOID;
        } else if (targetMethod.returnType().kind() == Type.Kind.PARAMETERIZED_TYPE) {
            ParameterizedType parameterizedType = targetMethod.returnType().asParameterizedType();
            if (parameterizedType.name().equals(UNI) && (parameterizedType.arguments().size() == 1)) {
                if (parameterizedType.arguments().get(0).name().equals(VOID)) {
                    return ReturnType.UNI_VOID;
                }
            }
        }
        throw new RuntimeException("Method '" + targetMethod.name() + " of class '" + targetMethod.declaringClass().name()
                + "' cannot be used as a response filter as it does not declare 'void' or 'Uni<Void>' as its return type");
    }

    private Class<?> determineRequestInterfaceType(ReturnType returnType) {
        switch (returnType) {
            case VOID:
            case OPTIONAL_RESPONSE:
            case OPTIONAL_REST_RESPONSE:
            case RESPONSE:
            case REST_RESPONSE:
                return ContainerRequestFilter.class;
            case UNI_RESPONSE:
            case UNI_REST_RESPONSE:
            case UNI_VOID:
                return ResteasyReactiveContainerRequestFilter.class;
            default:
                throw new IllegalStateException("ReturnType: '" + returnType + "' is not supported");
        }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Change the return type to void (most common).
  2. Use Uni<Void> if the filter is reactive.
  3. Move logic that must return a Response to a @ServerRequestFilter.
  4. Remove the annotation if the method is not meant to be a filter.

Example fix

// before
@ServerResponseFilter
public Uni<Response> postProcess(ContainerResponseContext ctx) { ... }
// after
@ServerResponseFilter
public void postProcess(ContainerResponseContext ctx) { ... }
Defensive patterns

Strategy: validation

Validate before calling

import java.lang.reflect.Method;

void validateResponseFilterReturnType(Method m) {
    Class<?> rt = m.getReturnType();
    boolean ok = rt == void.class || rt.getName().equals("io.smallrye.mutiny.Uni");
    if (!ok) throw new IllegalStateException(
        "@ServerResponseFilter must return void or Uni<Void>, found: " + rt.getName());
}

Prevention

When it happens

Trigger: Annotating a method with @ServerResponseFilter that returns Response, Uni<Response>, Optional<Response>, String or CompletionStage<Void>, then building the application.

Common situations: Copying a signature from a @ServerRequestFilter (Response returns are request-filter-only); trying to replace the response from a response filter (use ContainerResponseContext.setEntity instead); using CompletionStage instead of Uni.

Related errors


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