{"record":{"id":"c71ef92b0dc26c02","repo":"quarkusio/quarkus","slug":"calling-abortwith-is-not-permitted-when-using-s","errorCode":null,"errorMessage":"Calling 'abortWith' is not permitted when using @ServerRequestFilter or @ServerResponseFilter. If you need to abort processing, consider returning 'Response' or 'Uni<Response>'","messagePattern":"Calling 'abortWith' is not permitted when using @ServerRequestFilter or @ServerResponseFilter\\. If you need to abort processing, consider returning 'Response' or 'Uni<Response>'","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/filters/PreventAbortResteasyReactiveContainerRequestContext.java","lineNumber":160,"sourceCode":"\n    @Override\n    public void setEntityStream(InputStream input) {\n        delegate.setEntityStream(input);\n    }\n\n    @Override\n    public SecurityContext getSecurityContext() {\n        return delegate.getSecurityContext();\n    }\n\n    @Override\n    public void setSecurityContext(SecurityContext context) {\n        delegate.setSecurityContext(context);\n    }\n\n    @Override\n    public void abortWith(Response response) {\n        throw new IllegalStateException(\n                \"Calling 'abortWith' is not permitted when using @ServerRequestFilter or @ServerResponseFilter. If you need to abort processing, consider returning 'Response' or 'Uni<Response>'\");\n    }\n}\n","sourceCodeStart":142,"sourceCodeEnd":164,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/filters/PreventAbortResteasyReactiveContainerRequestContext.java#L142-L164","documentation":"When a method annotated with @ServerRequestFilter/@ServerResponseFilter runs, RESTEasy Reactive wraps the ContainerRequestContext in PreventAbortResteasyReactiveContainerRequestContext, which forbids abortWith. Filters must signal abortion by returning Response (or Uni<Response>) instead of manipulating the JAX-RS abort state; violating this throws IllegalStateException.","triggerScenarios":"Inside a @ServerRequestFilter method, calling ContainerRequestContext.abortWith(response) (directly or via legacy code reused from a @PreMatching/@NameBinding filter).","commonSituations":"Migrating classic JAX-RS ContainerRequestFilter code into a @ServerRequestFilter without adapting the abort logic; shared filter helper that calls abortWith unconditionally.","solutions":["Change the filter to return Response instead: `public Response filter(ContainerRequestContext ctx) { return Response.status(401).build(); }` (returning non-null aborts the request).","Return Uni<Response> for asynchronous aborts.","Move the abortWith-based logic into a classic ContainerRequestFilter (@Provider) if you must use abortWith.","Refactor shared helper methods to return an Optional<Response> the filter returns rather than calling abortWith."],"exampleFix":"// before\n@ServerRequestFilter\npublic void filter(ContainerRequestContext ctx) {\n    if (!authorized(ctx)) ctx.abortWith(Response.status(401).build());\n}\n// after\n@ServerRequestFilter\npublic Response filter(ContainerRequestContext ctx) {\n    if (!authorized(ctx)) return Response.status(401).build();\n    return null; // continue\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// avoid triggering; if calling legacy filter code, guard:\ntry {\n    legacyFilter.filter(requestContext);\n} catch (IllegalStateException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"abortWith\")) {\n        log.warn(\"Legacy filter attempted abortWith inside @ServerRequestFilter\");\n    } else throw e;\n}","preventionTips":["In @ServerRequestFilter, always abort by returning Response / Uni<Response>.","Audit migrated JAX-RS filters for abortWith calls.","Keep legacy ContainerRequestFilters as @Provider beans, not @ServerRequestFilter, if they need abortWith."],"tags":["resteasy-reactive","filters","illegalstate","migration"],"backgroundTag":"abort-with-forbidden-in-filter","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"}