{"record":{"id":"85be073c1fb6f15f","repo":"quarkusio/quarkus","slug":"response-has-been-closed-85be07","errorCode":null,"errorMessage":"Response has been closed","messagePattern":"Response has been closed","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/RestResponseImpl.java","lineNumber":210,"sourceCode":"                    while ((read = entityStream.read(buffer)) != -1) {\n                        os.write(buffer, 0, read);\n                    }\n                    entityStream.close();\n                } catch (IOException x) {\n                    throw new UncheckedIOException(x);\n                }\n                entityStream = new ByteArrayInputStream(os.toByteArray());\n            }\n            buffered = true;\n            return true;\n        }\n        return false;\n    }\n\n    protected void checkClosed() {\n        // apparently the TCK says that buffered responses don't care about being closed\n        if (closed && !buffered)\n            throw new IllegalStateException(\"Response has been closed\");\n    }\n\n    @Override\n    public void close() {\n        if (!closed) {\n            closed = true;\n            if (entityStream != null) {\n                try {\n                    entityStream.close();\n                } catch (IOException e) {\n                    throw new ProcessingException(e);\n                }\n            }\n        }\n    }\n\n    @Override\n    public MediaType getMediaType() {","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/RestResponseImpl.java#L192-L228","documentation":"RestResponseImpl.checkClosed throws IllegalStateException when any entity-related method is invoked after the response has been closed, unless the response was buffered. The JAX-RS Response lifecycle forbids access to the entity stream after close(); buffered responses keep their data in memory and are exempt per the TCK.","triggerScenarios":"Calling getEntity(), readEntity(), hasEntity(), or bufferEntity() after close() has been called on a non-buffered RestResponse; using try-with-resources on a response and then reading the entity outside the block; response auto-closed by a framework/interceptor before your read.","commonSituations":"try-with-resources pattern where readEntity happens after the resource block; leaking a response across async boundaries after it was closed; reading the entity in a finally or later callback after close.","solutions":["Call bufferEntity() before close() if you need the entity afterwards","Move all entity reads inside the try-with-resources block, before close()","Do not close the response until entity processing is complete","Restructure to consume the entity immediately when the response is received"],"exampleFix":"// before\ntry (RestResponse<Foo> r = client.call()) {\n    // no read here\n}\nFoo f = r.readEntity(Foo.class); // IllegalStateException\n// after\nFoo f;\ntry (RestResponse<Foo> r = client.call()) {\n    f = r.readEntity(Foo.class);\n}","handlingStrategy":"validation","validationCode":"if (response.isClosed() && !response.isBuffered()) {\n    throw new IllegalStateException(\"Refusing to read from closed response\");\n}","typeGuard":"boolean usable(RestResponse<?> r) {\n    return r != null && (!r.isClosed() || r.isBuffered());\n}","tryCatchPattern":"try {\n    return response.readEntity(String.class);\n} catch (IllegalStateException e) {\n    log.warn(\"Response already closed\");\n    return null;\n}","preventionTips":["Read the entity inside the try-with-resources block","Call bufferEntity() before close() when deferring reads","Never pass Response objects across async boundaries after closing","Consume entity immediately after receiving the response"],"tags":["jaxrs","rest-client","response-lifecycle","illegal-state"],"backgroundTag":"response-already-closed","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}