{"record":{"id":"28cffe3236d64638","repo":"jwtk/jjwt","slug":"unable-to-codecname-encode-name-t-getmess","errorCode":null,"errorMessage":"Unable to ${codecName}-encode ${name}: ${t.getMessage()}","messagePattern":"Unable to (.+?)-encode (.+?): (.+?)","errorType":"exception","errorClass":"io.jsonwebtoken.io.EncodingException","httpStatus":null,"severity":"error","filePath":"impl/src/main/java/io/jsonwebtoken/impl/io/EncodingOutputStream.java","lineNumber":37,"sourceCode":"import io.jsonwebtoken.lang.Assert;\n\nimport java.io.OutputStream;\n\npublic class EncodingOutputStream extends FilteredOutputStream {\n\n    private final String codecName;\n    private final String name;\n\n    public EncodingOutputStream(OutputStream out, String codecName, String name) {\n        super(out);\n        this.codecName = Assert.hasText(codecName, \"codecName cannot be null or empty.\");\n        this.name = Assert.hasText(name, \"name cannot be null or empty.\");\n    }\n\n    @Override\n    protected void onThrowable(Throwable t) {\n        String msg = \"Unable to \" + this.codecName + \"-encode \" + this.name + \": \" + t.getMessage();\n        throw new EncodingException(msg, t);\n    }\n}\n","sourceCodeStart":19,"sourceCodeEnd":40,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/impl/src/main/java/io/jsonwebtoken/impl/io/EncodingOutputStream.java#L19-L40","documentation":"Thrown as an EncodingException when an encoding stream operation fails while encoding the named value with the configured codec. EncodingOutputStream catches any Throwable raised while writing/encoding and rewraps it, preserving the cause. The message names the codec and the logical name of what was being encoded.","triggerScenarios":"Writing a JWT/JWS/JWE component through EncodingOutputStream when the underlying OutputStream throws an IOException (broken stream, disk full, closed pipe) or the codec rejects the byte content.","commonSituations":"Serializing a large claims payload to a stream backed by a closed socket or file; providing null/empty content that the codec rejects; container output stream already closed.","solutions":["Inspect the exception cause to find the underlying write or codec failure.","Verify the target OutputStream is open and writable for the duration of the encoding operation.","Check that the data being encoded is byte-encodable (no null byte arrays, no oversized payload).","If streaming to a servlet response or network socket, ensure it has not been committed/closed before encoding."],"exampleFix":"// before\nOutputStream out = response.getOutputStream(); // may already be committed/closed\nnew EncodingOutputStream(out, ...).write(data);\n// after\nif (!response.isCommitted()) {\n    OutputStream out = response.getOutputStream();\n    new EncodingOutputStream(out, ...).write(data);\n}","handlingStrategy":"try-catch","validationCode":"// Java\nif (out == null) throw new IllegalArgumentException(\"OutputStream cannot be null\");\nif (data == null || data.length == 0) throw new IllegalArgumentException(\"nothing to encode\");","typeGuard":null,"tryCatchPattern":"try (OutputStream safeOut = ensureOpen(out)) {\n    encoder.encodeTo(safeOut, data);\n} catch (EncodingException e) {\n    log.error(\"Failed to encode {}: {}\", name, e.getMessage(), e.getCause());\n    throw new IOException(\"Encoding failed\", e);\n}","preventionTips":["Use try-with-resources so output streams are properly managed and closed once.","Verify the target stream is not committed/closed before beginning encoding.","Keep payload sizes within transport limits (HTTP header ~8KB, etc.).","Check the cause of EncodingException to distinguish codec failures from IO failures."],"tags":["encoding","stream","io"],"backgroundTag":"json-serialization-failed","analyzedSha":"fb71496164c71442d08adec4571d9616ed5e1b8d","analyzedAt":"2026-09-09T00:33:09.982Z","contentChangedAt":"2026-09-09T00:33:09.982Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}