{"record":{"id":"5ee1d0e4874d157a","repo":"jwtk/jjwt","slug":"unable-to-codecname-decode-name-t-getmess","errorCode":null,"errorMessage":"Unable to ${codecName}-decode ${name}: ${t.getMessage()}","messagePattern":"Unable to (.+?)-decode (.+?): (.+?)","errorType":"validation","errorClass":"io.jsonwebtoken.io.DecodingException","httpStatus":null,"severity":"error","filePath":"impl/src/main/java/io/jsonwebtoken/impl/io/DecodingInputStream.java","lineNumber":37,"sourceCode":"import io.jsonwebtoken.lang.Assert;\n\nimport java.io.InputStream;\n\npublic class DecodingInputStream extends FilteredInputStream {\n\n    private final String codecName;\n    private final String name;\n\n    public DecodingInputStream(InputStream in, String codecName, String name) {\n        super(in);\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 + \"-decode \" + this.name + \": \" + t.getMessage();\n        throw new DecodingException(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/DecodingInputStream.java#L19-L40","documentation":"Thrown as a DecodingException when a decoding stream operation fails while Base64/base64url-decoding the named input. The wrapper class (DecodingInputStream) catches any Throwable raised during codec-decoding and rewraps it with a message naming the codec and the input name. The original cause is preserved as the exception cause for diagnosis.","triggerScenarios":"Reading a JWT, JWS, or JWE compact part through DecodingInputStream when the underlying bytes are not valid base64url, or when the underlying InputStream throws (IO failure, truncated stream).","commonSituations":"Hand-editing tokens and introducing invalid characters (e.g. '+', '/', '=' or whitespace) into a base64url segment; tokens truncated by proxies or logs; passing raw binary data where a base64url string was expected.","solutions":["Inspect the exception cause to see the underlying decode error (often IllegalArgumentException for bad characters).","Verify the input contains only base64url-safe characters (A-Z, a-z, 0-9, '-', '_') with no padding, whitespace, or line breaks.","Ensure the token is complete and not truncated by transport (URL length limits, logging truncation).","If the data came from another system, confirm it used base64url encoding, not standard Base64."],"exampleFix":"// before\nString token = someHeaderValue; // may contain '=' padding or whitespace\n// after\nString token = someHeaderValue.trim().replace(\"=\", \"\").replace(\"+\", \"-\").replace(\"/\", \"_\");","handlingStrategy":"try-catch","validationCode":"// Java\nprivate static final Pattern B64URL = Pattern.compile(\"^[A-Za-z0-9_-]*$\");\nif (!B64URL.matcher(segment).matches()) {\n    throw new IllegalArgumentException(\"segment contains invalid base64url characters\");\n}","typeGuard":"static boolean isBase64Url(String s) {\n    return s != null && s.matches(\"[A-Za-z0-9_-]*\");\n}","tryCatchPattern":"try {\n    byte[] decoded = Decoders.BASE64URL.decode(segment);\n} catch (DecodingException e) {\n    log.warn(\"Invalid base64url segment: {}\", e.getMessage(), e.getCause());\n    throw new BadRequestException(\"Malformed token\");\n}","preventionTips":["Reject tokens with invalid base64url characters at your API boundary before invoking the parser.","Trim whitespace and strip '=' padding from tokens received via headers or query params.","Log the exception cause, not just the message, to diagnose character-level decode failures.","Never round-trip JWTs through systems that re-encode strings (URL encoders, HTML escape layers)."],"tags":["base64url","decoding","jwt","io"],"backgroundTag":"json-decode-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"}