{"record":{"id":"98cc7b8d25984f03","repo":"jwtk/jjwt","slug":"msg","errorCode":null,"errorMessage":"${msg}","messagePattern":"\\$\\{msg\\}","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/io/jsonwebtoken/lang/Assert.java","lineNumber":237,"sourceCode":"     * @param array the array to check\n     * @throws IllegalArgumentException if the object array is <code>null</code> or has no elements\n     */\n    public static void notEmpty(Object[] array) {\n        notEmpty(array, \"[Assertion failed] - this array must not be empty: it must contain at least 1 element\");\n    }\n\n    /**\n     * Assert that the specified byte array is not null and has at least one byte element.\n     *\n     * @param array the byte array to check\n     * @param msg   the exception message to use if the assertion fails\n     * @return the byte array if the assertion passes\n     * @throws IllegalArgumentException if the byte array is null or empty\n     * @since 0.12.0\n     */\n    public static byte[] notEmpty(byte[] array, String msg) {\n        if (Objects.isEmpty(array)) {\n            throw new IllegalArgumentException(msg);\n        }\n        return array;\n    }\n\n    /**\n     * Assert that the specified character array is not null and has at least one byte element.\n     *\n     * @param chars the character array to check\n     * @param msg   the exception message to use if the assertion fails\n     * @return the character array if the assertion passes\n     * @throws IllegalArgumentException if the character array is null or empty\n     * @since 0.12.0\n     */\n    public static char[] notEmpty(char[] chars, String msg) {\n        if (Objects.isEmpty(chars)) {\n            throw new IllegalArgumentException(msg);\n        }\n        return chars;","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/api/src/main/java/io/jsonwebtoken/lang/Assert.java#L219-L255","documentation":"Thrown by io.jsonwebtoken.lang.Assert.notEmpty(byte[], String) (since 0.12.0) when the supplied byte array is null or empty. JJWT uses it to reject empty key material or other byte-based inputs, since cryptographic operations require at least one byte. It throws java.lang.IllegalArgumentException with the caller's message and returns the array when valid.","triggerScenarios":"Calling Assert.notEmpty(byte[] array, msg) with array == null or array.length == 0; passing empty key bytes to key builders (SecretKeySpec-style construction), signing keys, or claim values routed through this assertion.","commonSituations":"Reading a signing key from an env var or file that resolved to empty bytes (missing file, blank env variable); decoding a base64 key string that failed silently and produced a zero-length array; supplying an empty PEM/DER payload to a key parser.","solutions":["Verify the byte array's source (file, env var, decoder) actually produced bytes; log array.length before the call.","Fix the key loading path: correct the file path/env var and confirm the decode produced data.","Fail fast with your own check so the error message points at the real configuration problem."],"exampleFix":"// before\nbyte[] keyBytes = Base64.getDecoder().decode(System.getenv(\"JWT_SECRET\")); // blank -> may throw or yield empty\nKeys.hmacShaKeyFor(keyBytes);\n// after\nString secret = System.getenv(\"JWT_SECRET\");\nAssert.notNull(secret, \"JWT_SECRET not set\");\nbyte[] keyBytes = Base64.getDecoder().decode(secret);\nif (keyBytes.length == 0) throw new IllegalArgumentException(\"JWT_SECRET decodes to empty bytes\");\nKeys.hmacShaKeyFor(keyBytes);","handlingStrategy":"validation","validationCode":"if (keyBytes == null || keyBytes.length == 0) {\n    throw new IllegalArgumentException(\"key bytes are missing or empty\");\n}","typeGuard":"boolean hasBytes(byte[] b) { return b != null && b.length > 0; }","tryCatchPattern":"try {\n    SecretKey key = Keys.hmacShaKeyFor(keyBytes);\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"Invalid key material: \" + e.getMessage(), e);\n}","preventionTips":["Verify env vars/files supplying key material are non-blank at startup.","Log key byte length (never the bytes) before use.","Wrap secret decoding with explicit empty-result checks."],"tags":["java","assertion","empty-array","key-material"],"backgroundTag":"empty-required-field","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"}