quarkusio/quarkus · error · IllegalStateException

Setting both 'readBody' and 'preMatching' to 'true' on '@Ser

Error message

Setting both 'readBody' and 'preMatching' to 'true' on '@ServerRequestFilter' is invalid. Offending method is '${methodInfo.name()}' of class '${methodInfo.declaringClass().name()}'

What it means

@ServerRequestFilter(readBody = true) requires the request body to be readable, which only happens after resource matching; preMatching = true means the filter runs before matching. The two are mutually exclusive, so FilterGeneration throws IllegalStateException at build time when both are true on the same filter method.

Source

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

            if (priorityValue != null) {
                priority = priorityValue.asInt();
            }
            AnnotationValue preMatchingValue = instance.value("preMatching");
            if (preMatchingValue != null) {
                preMatching = preMatchingValue.asBoolean();
            }
            AnnotationValue nonBlockingRequiredValue = instance.value("nonBlocking");
            if (nonBlockingRequiredValue != null) {
                nonBlockingRequired = nonBlockingRequiredValue.asBoolean();
            }
            AnnotationValue readBodyValue = instance.value("readBody");
            if (readBodyValue != null) {
                readBody = readBodyValue.asBoolean();
            }

            if (preMatching) {
                if (readBody) {
                    throw new IllegalStateException(
                            "Setting both 'readBody' and 'preMatching' to 'true' on '@ServerRequestFilter' is invalid. Offending method is '"
                                    + methodInfo.name() + "' of class '" + methodInfo.declaringClass().name() + "'");
                }
                if (withFormRead) {
                    throw new IllegalStateException(
                            "Setting both '@WithFormRead' and 'preMatching' to 'true' on '@ServerRequestFilter' is invalid. Offending method is '"
                                    + methodInfo.name() + "' of class '" + methodInfo.declaringClass().name() + "'");
                }
            }

            List<AnnotationInstance> annotations = methodInfo.annotations();
            for (AnnotationInstance annotation : annotations) {
                if (SERVER_REQUEST_FILTER.equals(annotation.name())) {
                    continue;
                }
                DotName annotationDotName = annotation.name();
                ClassInfo annotationClassInfo = index.getClassByName(annotationDotName);
                if (annotationClassInfo == null) {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Remove `readBody = true` if the filter only needs URI/headers.
  2. Remove `preMatching = true` if the filter genuinely needs the body, letting it run post-match.
  3. Split into two filters: one pre-matching, one reading the body.
  4. Handle body inspection at a gateway/proxy layer if it must happen before matching.

Example fix

// before
@ServerRequestFilter(preMatching = true, readBody = true)
public void filter(ContainerRequestContext ctx) { ... }
// after
@ServerRequestFilter(preMatching = true)
public void filter(ContainerRequestContext ctx) { /* no body access */ }
Defensive patterns

Strategy: validation

Validate before calling

// reflection-based check before build:
ServerRequestFilter ann = filterMethod.getAnnotation(ServerRequestFilter.class);
if (ann != null && ann.preMatching() && ann.readBody()) {
    throw new IllegalStateException(
        "readBody + preMatching not allowed on " + filterMethod);
}

Prevention

When it happens

Trigger: Declaring `@ServerRequestFilter(preMatching = true, readBody = true)` on a filter method and building the application.

Common situations: Wanting the request body in a pre-match filter (e.g. content-based routing) which is unsupported; copy-pasting annotation attributes between filters; enabling readBody 'just in case'.

Related errors


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