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 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 What it means
A @ServerRequestFilter method must return one of: void, Response, RestResponse, Optional<Response>, Optional<RestResponse>, Uni<Void>, Uni<Response> or Uni<RestResponse>. The generated filter machinery relies on the return value to decide whether to abort the request chain. determineRequestFilterReturnType throws if the return type maps to none of these.
Source
Thrown at independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/generation/filters/CustomFilterGenerator.java:741
return ReturnType.UNI_VOID;
} else if (parameterizedType.arguments().get(0).name().equals(RESPONSE)) {
return ReturnType.UNI_RESPONSE;
} else if (parameterizedType.arguments().get(0).name().equals(REST_RESPONSE)) {
return ReturnType.UNI_REST_RESPONSE;
}
} else if (parameterizedType.name().equals(OPTIONAL) && (parameterizedType.arguments().size() == 1)) {
if (parameterizedType.arguments().get(0).name().equals(RESPONSE)) {
return ReturnType.OPTIONAL_RESPONSE;
} else if (parameterizedType.arguments().get(0).name().equals(REST_RESPONSE)) {
return ReturnType.OPTIONAL_REST_RESPONSE;
}
} else if (parameterizedType.name().equals(REST_RESPONSE)) {
return ReturnType.REST_RESPONSE;
}
} 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");
}
View on GitHub (pinned to e1c734241f)
Solutions
- Return void if the filter never aborts the request.
- Return Response (or Optional<Response>) to conditionally abort with a custom response.
- For reactive filters use Uni<Void>, Uni<Response> or Uni<RestResponse>, not CompletionStage.
- Remove the @ServerRequestFilter annotation if the method is not intended as a filter.
Example fix
// before
@ServerRequestFilter
public boolean check(ContainerRequestContext ctx) { return true; }
// after
@ServerRequestFilter
public void check(ContainerRequestContext ctx) { /* return Response to abort */ } Defensive patterns
Strategy: validation
Validate before calling
import java.lang.reflect.Method;
import java.util.Set;
void validateRequestFilterReturnType(Method m) {
Class<?> rt = m.getReturnType();
boolean ok = rt == void.class
|| rt.getName().equals("jakarta.ws.rs.core.Response")
|| rt == java.util.Optional.class
|| rt.getName().equals("io.smallrye.mutiny.Uni");
if (!ok) throw new IllegalStateException(
"Unsupported @ServerRequestFilter return type: " + rt.getName());
} Prevention
- Use only documented return types: void, Response, RestResponse, Optional<Response/RestResponse>, Uni<Void/Response/RestResponse>.
- Never return boolean or CompletionStage from filters.
- Import jakarta.ws.rs.core.Response, not a same-named custom class.
- Consult the @ServerRequestFilter Javadoc when unsure of the signature.
When it happens
Trigger: Annotating a method with @ServerRequestFilter whose return type is anything else (String, boolean, Uni<String>, CompletionStage<Response>, custom POJO) and building the application.
Common situations: Returning boolean intending 'continue or abort'; returning Uni<String> instead of Uni<Response>; using CompletionStage instead of the supported Uni type; accidentally importing a custom Response class instead of jakarta.ws.rs.core.Response.
Related errors
- Method '${targetMethod.name()} of class '${targetMethod.decl
- The combination of '@${annotationName}' and '@ServerRequestF
- Method '${info.name()} of class '${info.declaringClass().nam
- Method '${info.name()} of class '${info.declaringClass().nam
- ${className} class reading failed
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/96d85c80f42f8c28.
Report an issue: GitHub.