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
- Remove `readBody = true` if the filter only needs URI/headers.
- Remove `preMatching = true` if the filter genuinely needs the body, letting it run post-match.
- Split into two filters: one pre-matching, one reading the body.
- 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
- Pre-matching filters run before routing — body/form reading is impossible there.
- Only set readBody = true when the body is actually needed.
- Split body-dependent logic into a post-match filter.
- Re-read the @ServerRequestFilter attribute docs before combining flags.
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
- Setting both '@WithFormRead' and 'preMatching' to 'true' on
- The configuration ${clazz} is missing the @ConfigRoot annota
- Invalid configuration value set for 'quarkus.arc.remove-unus
- Hibernate Envers activated explicitly for persistence unit '
- The FastbootHibernateProvider PersistenceProvider can not su
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/19c9a8461dc47075.
Report an issue: GitHub.