{"record":{"id":"19c9a8461dc47075","repo":"quarkusio/quarkus","slug":"setting-both-readbody-and-prematching-to-true","errorCode":null,"errorMessage":"Setting both 'readBody' and 'preMatching' to 'true' on '@ServerRequestFilter' is invalid. Offending method is '${methodInfo.name()}' of class '${methodInfo.declaringClass().name()}'","messagePattern":"Setting both 'readBody' and 'preMatching' to 'true' on '@ServerRequestFilter' is invalid\\. Offending method is '(.+?)' of class '(.+?)'","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/generation/filters/FilterGeneration.java","lineNumber":63,"sourceCode":"            if (priorityValue != null) {\n                priority = priorityValue.asInt();\n            }\n            AnnotationValue preMatchingValue = instance.value(\"preMatching\");\n            if (preMatchingValue != null) {\n                preMatching = preMatchingValue.asBoolean();\n            }\n            AnnotationValue nonBlockingRequiredValue = instance.value(\"nonBlocking\");\n            if (nonBlockingRequiredValue != null) {\n                nonBlockingRequired = nonBlockingRequiredValue.asBoolean();\n            }\n            AnnotationValue readBodyValue = instance.value(\"readBody\");\n            if (readBodyValue != null) {\n                readBody = readBodyValue.asBoolean();\n            }\n\n            if (preMatching) {\n                if (readBody) {\n                    throw new IllegalStateException(\n                            \"Setting both 'readBody' and 'preMatching' to 'true' on '@ServerRequestFilter' is invalid. Offending method is '\"\n                                    + methodInfo.name() + \"' of class '\" + methodInfo.declaringClass().name() + \"'\");\n                }\n                if (withFormRead) {\n                    throw new IllegalStateException(\n                            \"Setting both '@WithFormRead' and 'preMatching' to 'true' on '@ServerRequestFilter' is invalid. Offending method is '\"\n                                    + methodInfo.name() + \"' of class '\" + methodInfo.declaringClass().name() + \"'\");\n                }\n            }\n\n            List<AnnotationInstance> annotations = methodInfo.annotations();\n            for (AnnotationInstance annotation : annotations) {\n                if (SERVER_REQUEST_FILTER.equals(annotation.name())) {\n                    continue;\n                }\n                DotName annotationDotName = annotation.name();\n                ClassInfo annotationClassInfo = index.getClassByName(annotationDotName);\n                if (annotationClassInfo == null) {","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/generation/filters/FilterGeneration.java#L45-L81","documentation":"@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.","triggerScenarios":"Declaring `@ServerRequestFilter(preMatching = true, readBody = true)` on a filter method and building the application.","commonSituations":"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'.","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."],"exampleFix":"// before\n@ServerRequestFilter(preMatching = true, readBody = true)\npublic void filter(ContainerRequestContext ctx) { ... }\n// after\n@ServerRequestFilter(preMatching = true)\npublic void filter(ContainerRequestContext ctx) { /* no body access */ }","handlingStrategy":"validation","validationCode":"// reflection-based check before build:\nServerRequestFilter ann = filterMethod.getAnnotation(ServerRequestFilter.class);\nif (ann != null && ann.preMatching() && ann.readBody()) {\n    throw new IllegalStateException(\n        \"readBody + preMatching not allowed on \" + filterMethod);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["quarkus","resteasy-reactive","build-time","serverrequestfilter","configuration"],"backgroundTag":"conflicting-filter-options","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}