jwtk/jjwt · error · java.lang.IllegalArgumentException

Cannot decode input String. Cause: ${e.getMessage()}

Error message

Cannot decode input String. Cause: ${e.getMessage()}

What it means

Thrown by Codec.applyFrom when the configured Decoder rejects the input CharSequence — the string is not valid for the codec's encoding (e.g. malformed Base64/Base64URL when decoding a compact JWT/JWK segment). The DecodingException's message is wrapped as the cause; this is a data-format failure of the supplied text, not a configuration problem.

Source

Thrown at impl/src/main/java/io/jsonwebtoken/impl/io/Codec.java:50

    private final Decoder<CharSequence, byte[]> decoder;

    public Codec(Encoder<byte[], String> encoder, Decoder<CharSequence, byte[]> decoder) {
        this.encoder = Assert.notNull(encoder, "Encoder cannot be null.");
        this.decoder = Assert.notNull(decoder, "Decoder cannot be null.");
    }

    @Override
    public String applyTo(byte[] a) {
        return this.encoder.encode(a);
    }

    @Override
    public byte[] applyFrom(CharSequence b) {
        try {
            return this.decoder.decode(b);
        } catch (DecodingException e) {
            String msg = "Cannot decode input String. Cause: " + e.getMessage();
            throw new IllegalArgumentException(msg, e);
        }
    }
}

View on GitHub (pinned to fb71496164)

Solutions

  1. Inspect the cause message to identify the exact encoding defect (illegal character, bad padding, strict-decoding violation)
  2. Verify the input string is complete and unmodified — no truncation, whitespace, or URL-safety mixing (use Base64URL for JWT segments)
  3. Re-obtain or re-encode the value from the source; do not attempt to 'repair' encoded payloads by hand
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at impl/src/main/java/io/jsonwebtoken/impl/io/Codec.java:50 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of jwtk/jjwt@fb71496164 (2026-09-09). Data as JSON: /api/errors/1f5743c33ad323be. Report an issue: GitHub.