quarkusio/quarkus · error · IllegalStateException
Setting both '@WithFormRead' and 'preMatching' to 'true' on
Error message
Setting both '@WithFormRead' and 'preMatching' to 'true' on '@ServerRequestFilter' is invalid. Offending method is '${methodInfo.name()}' of class '${methodInfo.declaringClass().name()}' What it means
@WithFormRead forces the filter to run after form parameters are read, which requires the request to have been matched; a pre-matching filter runs before matching. Combining @WithFormRead with preMatching = true on @ServerRequestFilter is contradictory and rejected at build time by FilterGeneration.
Source
Thrown at independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/generation/filters/FilterGeneration.java:68
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) {
continue;
}
if ((annotationClassInfo.declaredAnnotation(ResteasyReactiveDotNames.NAME_BINDING) != null)) {
nameBindingNames.add(annotationDotName.toString());
}View on GitHub (pinned to e1c734241f)
Solutions
- Remove @WithFormRead if the pre-matching filter does not need form parameters.
- Remove `preMatching = true` so the filter runs post-match with form data available.
- Split into two filters: a pre-matching check and a post-match form-reading filter.
Example fix
// before
@WithFormRead
@ServerRequestFilter(preMatching = true)
public void filter(ContainerRequestContext ctx) { ... }
// after
@WithFormRead
@ServerRequestFilter
public void filter(ContainerRequestContext ctx) { /* form data accessible */ } Defensive patterns
Strategy: validation
Validate before calling
// @WithFormRead + preMatching = true is invalid; enforce at review/test time:
WithFormRead wf = filterMethod.getAnnotation(WithFormRead.class);
ServerRequestFilter f = filterMethod.getAnnotation(ServerRequestFilter.class);
if (wf != null && f != null && f.preMatching()) {
throw new IllegalStateException(
"@WithFormRead cannot be combined with preMatching on " + filterMethod);
} Prevention
- Form parameter access requires a post-match filter; never annotate pre-matching filters with @WithFormRead.
- Split into a pre-matching filter and a post-match form-reading filter.
- Avoid copy-pasting @WithFormRead between filters.
- Verify annotation combinations in a unit test using reflection.
When it happens
Trigger: Declaring `@ServerRequestFilter(preMatching = true)` on a method also annotated with `@WithFormRead` and building the application.
Common situations: Needing form parameters (application/x-www-form-urlencoded) inside a pre-match authorization filter; adding @WithFormRead via copy-paste from another filter.
Related errors
- Setting both 'readBody' and 'preMatching' to 'true' on '@Ser
- 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/0aa69c11f214c6a0.
Report an issue: GitHub.