{"record":{"id":"d59bb488f5142a0f","repo":"jwtk/jjwt","slug":"message","errorCode":null,"errorMessage":"${message}","messagePattern":"\\$\\{message\\}","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/io/jsonwebtoken/lang/Assert.java","lineNumber":41,"sourceCode":" * increasing cyclomatic complexity.\n */\npublic final class Assert {\n\n    private Assert() {\n    } //prevent instantiation\n\n    /**\n     * Assert a boolean expression, throwing <code>IllegalArgumentException</code>\n     * if the test result is <code>false</code>.\n     * <pre class=\"code\">Assert.isTrue(i &gt; 0, \"The value must be greater than zero\");</pre>\n     *\n     * @param expression a boolean expression\n     * @param message    the exception message to use if the assertion fails\n     * @throws IllegalArgumentException if expression is <code>false</code>\n     */\n    public static void isTrue(boolean expression, String message) {\n        if (!expression) {\n            throw new IllegalArgumentException(message);\n        }\n    }\n\n    /**\n     * Assert a boolean expression, throwing <code>IllegalArgumentException</code>\n     * if the test result is <code>false</code>.\n     * <pre class=\"code\">Assert.isTrue(i &gt; 0);</pre>\n     *\n     * @param expression a boolean expression\n     * @throws IllegalArgumentException if expression is <code>false</code>\n     */\n    public static void isTrue(boolean expression) {\n        isTrue(expression, \"[Assertion failed] - this expression must be true\");\n    }\n\n    /**\n     * Assert that an object is <code>null</code> .\n     * <pre class=\"code\">Assert.isNull(value, \"The value must be null\");</pre>","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/api/src/main/java/io/jsonwebtoken/lang/Assert.java#L23-L59","documentation":"Assert.isTrue validates a boolean precondition and throws IllegalArgumentException with the caller-supplied message when the expression is false. The JJWT library uses it internally to enforce argument contracts before proceeding (e.g. key sizes, algorithm compatibility, positive numbers). It is a fail-fast guard, not a runtime state error.","triggerScenarios":"Any JJWT API call whose internal Assert.isTrue(expression, message) check evaluates false — e.g. passing a key whose bit length or algorithm does not satisfy a required predicate, or a numeric argument that must be > 0 but is 0/negative.","commonSituations":"Using an HMAC key shorter than the algorithm requires (e.g. 128-bit key for HS256 after upgrading), configuring a negative or zero clock-skew/lease value, or swapping arguments so a condition that was previously true becomes false.","solutions":["Read the exception message; it names the exact predicate that failed and the offending value.","Fix the argument so the stated condition holds (e.g. supply a key of sufficient length, a positive number).","Validate the value with an explicit check or Assert-style guard in your own code before calling the JJWT API so the failure surfaces at the call site.","Check version migration notes if the precondition changed after a library upgrade."],"exampleFix":"// before\nKey key = Keys.hmacShaKeyFor(shortSecret.getBytes()); // 10 bytes -> IllegalArgumentException\n// after\nbyte[] bytes = secret.getBytes(StandardCharsets.UTF_8);\nif (bytes.length < 32) { throw new IllegalArgumentException(\"HS256 needs >= 256-bit key\"); }\nSecretKey key = Keys.hmacShaKeyFor(bytes);","handlingStrategy":"validation","validationCode":"if (!(keyBytes.length * 8 >= 256)) {\n    throw new IllegalArgumentException(\"HS256 requires a key of at least 256 bits\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    // JJWT call with checked argument\n} catch (IllegalArgumentException e) {\n    log.error(\"invalid argument for JWT API: \" + e.getMessage());\n    throw new ConfigurationException(e.getMessage(), e);\n}","preventionTips":["Check numeric/size preconditions (key bit length, positive durations) at your config-loading boundary.","Log the offending value with the assertion message to make failures self-explanatory.","Re-read migration notes when upgrading JJWT; preconditions on keys/algorithms can tighten between versions."],"tags":["java","jjwt","illegal-argument","assertion","input-validation"],"backgroundTag":"invalid-argument-value","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"}