{"record":{"id":"c3141ad34814710c","repo":"jwtk/jjwt","slug":"io-exception-t-getmessage-c3141a","errorCode":null,"errorMessage":"IO Exception ${t.getMessage()}","messagePattern":"IO Exception (.+?)","errorType":"exception","errorClass":"java.io.IOException","httpStatus":null,"severity":"error","filePath":"impl/src/main/java/io/jsonwebtoken/impl/io/FilteredOutputStream.java","lineNumber":124,"sourceCode":"        try {\n            out.flush();\n        } catch (final Throwable t) {\n            onThrowable(t);\n        }\n    }\n\n    /**\n     * Handle any IOExceptions thrown.\n     * <p>\n     * This method provides a point to implement custom exception\n     * handling. The default behavior is to re-throw the exception.\n     *\n     * @param t The Throwable thrown\n     * @throws IOException if an I/O error occurs.\n     */\n    protected void onThrowable(final Throwable t) throws IOException {\n        if (t instanceof IOException) throw (IOException) t;\n        throw new IOException(\"IO Exception \" + t.getMessage(), t);\n    }\n\n    /**\n     * Invokes the delegate's {@code write(byte[])} method.\n     *\n     * @param bts the bytes to write\n     * @throws IOException if an I/O error occurs.\n     */\n    @Override\n    public void write(final byte[] bts) throws IOException {\n        try {\n            final int len = Bytes.length(bts);\n            beforeWrite(len);\n            out.write(bts);\n            afterWrite(len);\n        } catch (final Throwable t) {\n            onThrowable(t);\n        }","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/impl/src/main/java/io/jsonwebtoken/impl/io/FilteredOutputStream.java#L106-L142","documentation":"FilteredOutputStream wraps any non-IOException Throwable raised by write, flush, or close on its delegate into an IOException with the message 'IO Exception <msg>'. IOExceptions from the delegate are rethrown as-is.","triggerScenarios":"Writing, flushing, or closing a FilteredOutputStream whose delegate throws a non-IO Throwable (e.g. NullPointerException from an unset delegate, RuntimeException in a custom stream) or an underlying IO error.","commonSituations":"Output stream closed by the framework before all writes complete; broken pipe on socket-backed streams; flush() on a stream whose target (e.g. HTTP response) is already committed.","solutions":["Inspect the cause: native IOExceptions surface unchanged, so fix the underlying IO problem.","Ensure the output stream remains open until all writes and the final flush complete.","Check flush()/close() ordering — close the stream exactly once, in a finally block or try-with-resources.","For socket-backed streams, handle broken-pipe conditions on the transport layer."],"exampleFix":"// before\nout.write(bytes);\nout.flush();\n// after\ntry (OutputStream out = ...) {\n    out.write(bytes);\n    out.flush();\n} // closes exactly once, even on failure","handlingStrategy":"try-catch","validationCode":"// Java\nif (out == null) throw new IllegalArgumentException(\"OutputStream cannot be null\");\n// avoid writing to already-committed servlet responses\nif (response != null && response.isCommitted()) throw new IllegalStateException(\"response committed\");","typeGuard":null,"tryCatchPattern":"try {\n    filteredOut.write(bytes);\n    filteredOut.flush();\n} catch (IOException e) {\n    Throwable cause = e.getCause();\n    if (cause != null) log.error(\"Write failure root cause: {}\", cause.getMessage());\n    throw e;\n}","preventionTips":["Close output streams exactly once, using try-with-resources.","Flush before close; avoid double-close on container-managed streams.","For socket streams, handle broken pipes at the transport layer.","Verify delegate streams remain writable throughout the write sequence."],"tags":["io","stream","outputstream"],"backgroundTag":"file-write-failed","analyzedSha":"fb71496164c71442d08adec4571d9616ed5e1b8d","analyzedAt":"2026-09-09T00:33:09.982Z","contentChangedAt":"2026-09-09T00:33:09.982Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}