{"record":{"id":"f45594be6bfbb27d","repo":"quarkusio/quarkus","slug":"response-has-been-closed","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/ResponseImpl.java","lineNumber":190,"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":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/ResponseImpl.java#L172-L208","documentation":"ResponseImpl.checkClosed() throws IllegalStateException when a Response that was closed() and is not buffered is accessed. Once closed, the underlying connection/stream is released, so getEntity, readEntity, hasEntity and bufferEntity refuse to operate. Buffered responses are exempt per the JAX-RS TCK.","triggerScenarios":"Calling readEntity()/getEntity() on a Response after close(); using a Response outside a try-with-resources after it has been auto-closed; accessing a Response in a listener/callback that runs after the request completed.","commonSituations":"Double-consumption patterns where code closes the response then logs the entity; caching a Response field and reading it later; framework code (filters/interceptors) that closed the response before downstream code reads it.","solutions":["Read the entity BEFORE closing the response; close in a finally/try-with-resources after consumption.","Call bufferEntity() before close() if you need to access the entity multiple times or after closing.","Remove the duplicate close() or the late access; don't share Response objects across async boundaries after closing.","Restructure so the entity is extracted into a plain object within the response's scope."],"exampleFix":"// before\ntry (Response response = client.target(url).request().get()) { /* nothing read here */ }\nString body = response.readEntity(String.class); // IllegalStateException\n// after\nString body;\ntry (Response response = client.target(url).request().get()) {\n    body = response.readEntity(String.class);\n}","handlingStrategy":"try-catch","validationCode":"// guard before reading\nif (response instanceof ResponseImpl) { /* or track closed state yourself */ }\nboolean safeToRead = !responseClosed && (buffered || response.hasEntity());","typeGuard":"boolean canRead(javax.ws.rs.core.Response r) { try { return r.hasEntity(); } catch (IllegalStateException e) { return false; } }","tryCatchPattern":"try { return response.readEntity(String.class); } catch (IllegalStateException e) { log.warn(\"Response already closed; re-issue request or buffer beforehand\", e); return null; }","preventionTips":["Read the entity inside the try-with-resources scope before close()","Call bufferEntity() if you need the entity more than once or after closing","Don't leak Response objects out of request/async scopes","Centralize response consumption in one utility method"],"tags":["jax-rs","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"}