quarkusio/quarkus · error · RuntimeException
Method '${info.name()} of class '${info.declaringClass().nam
Error message
Method '${info.name()} of class '${info.declaringClass().name()}' cannot be static as it is annotated with '@${annotationDotName}' What it means
RESTEasy Reactive generates an instance-based filter class that invokes your annotated filter method; static methods cannot be dispatched that way. CustomFilterGenerator.checkModifiers inspects the MethodInfo flags and throws when a filter method is declared static.
Source
Thrown at independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/generation/filters/CustomFilterGenerator.java:711
ifNullBranch.falseBranch().assign(resourceInfo, ifNullBranch.falseBranch().invokeVirtualMethod(
MethodDescriptor.ofMethod(RuntimeResource.class, "getSimplifiedResourceInfo", SimpleResourceInfo.class),
runtimeResourceHandle));
return resourceInfo;
}
private String getGeneratedClassName(MethodInfo targetMethod, DotName annotationDotName) {
DotName declaringClassName = targetMethod.declaringClass().name();
return declaringClassName.toString() + "$Generated" + annotationDotName.withoutPackagePrefix() + "$"
+ targetMethod.name();
}
private void checkModifiers(MethodInfo info, DotName annotationDotName) {
if ((info.flags() & Modifier.PRIVATE) != 0) {
throw new RuntimeException("Method '" + info.name() + " of class '" + info.declaringClass().name()
+ "' cannot be private as it is annotated with '@" + annotationDotName + "'");
}
if ((info.flags() & Modifier.STATIC) != 0) {
throw new RuntimeException("Method '" + info.name() + " of class '" + info.declaringClass().name()
+ "' cannot be static as it is annotated with '@" + annotationDotName + "'");
}
}
private ReturnType determineRequestFilterReturnType(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;
} 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)) {View on GitHub (pinned to e1c734241f)
Solutions
- Remove the `static` modifier so the filter is an instance method.
- If the logic must stay static, add a non-static method carrying the filter annotation that delegates to the static one.
- Remove the filter annotation if the method is not meant to be a filter.
Example fix
// before
public static void authFilter(ContainerRequestContext ctx) { ... }
// after
public void authFilter(ContainerRequestContext ctx) { ... } Defensive patterns
Strategy: validation
Validate before calling
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
void validateFilterNotStatic(Class<?> filterClass) {
for (Method m : filterClass.getDeclaredMethods()) {
if (java.util.Arrays.stream(m.getAnnotations()).anyMatch(
a -> a.annotationType().getName().endsWith("Filter"))
&& Modifier.isStatic(m.getModifiers())) {
throw new IllegalStateException("Filter method must not be static: " + m);
}
}
} Prevention
- Filters must be instance methods — never static.
- Do not move annotated filter methods into static utility classes.
- Add an architecture test that flags static filter methods.
- If delegation to a static utility is needed, keep the annotated wrapper non-static.
When it happens
Trigger: Annotating a `static` method with @ServerRequestFilter/@ServerResponseFilter (or a custom filter annotation) and building the application.
Common situations: Writing filters as static utility methods out of habit; moving a filter into a utility class and making it static while keeping the annotation.
Related errors
- The combination of '@${annotationName}' and '@ServerRequestF
- Method '${info.name()} of class '${info.declaringClass().nam
- Method '${targetMethod.name()} of class '${targetMethod.decl
- Method '${targetMethod.name()} of class '${targetMethod.decl
- ${className} class reading failed
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/ec66cd3db5a3e772.
Report an issue: GitHub.