{"record":{"id":"593c6c14adc2e458","repo":"jwtk/jjwt","slug":"jwk-kty-value-cannot-be-empty","errorCode":null,"errorMessage":"JWK kty value cannot be empty.","messagePattern":"JWK kty value cannot be empty\\.","errorType":"validation","errorClass":"io.jsonwebtoken.security.MalformedKeyException","httpStatus":null,"severity":"error","filePath":"impl/src/main/java/io/jsonwebtoken/impl/security/JwkConverter.java","lineNumber":157,"sourceCode":"        // mandatory for all JWKs: https://datatracker.ietf.org/doc/html/rfc7517#section-4.1\n        // no need for builder param type conversion overhead if this isn't present:\n        if (Collections.isEmpty(map) || !map.containsKey(param.getId())) {\n            String msg = \"JWK is missing required \" + param + \" parameter.\";\n            throw new MalformedKeyException(msg);\n        }\n        Object val = map.get(param.getId());\n        if (val == null) {\n            String msg = \"JWK \" + param + \" value cannot be null.\";\n            throw new MalformedKeyException(msg);\n        }\n        if (!(val instanceof String)) {\n            String msg = \"JWK \" + param + \" value must be a String. Type found: \" + val.getClass().getName();\n            throw new MalformedKeyException(msg);\n        }\n        String kty = (String) val;\n        if (!Strings.hasText(kty)) {\n            String msg = \"JWK \" + param + \" value cannot be empty.\";\n            throw new MalformedKeyException(msg);\n        }\n\n        DynamicJwkBuilder<?, ?> builder = this.supplier.get();\n        for (Map.Entry<?, ?> entry : map.entrySet()) {\n            Object key = entry.getKey();\n            Assert.notNull(key, \"JWK map key cannot be null.\");\n            if (!(key instanceof String)) {\n                String msg = \"JWK map keys must be Strings. Encountered key '\" + key + \"' of type \" +\n                        key.getClass().getName() + \".\";\n                throw new IllegalArgumentException(msg);\n            }\n            String skey = (String) key;\n            builder.add(skey, entry.getValue());\n        }\n        Jwk<?> jwk = builder.build();\n\n        if (desiredType.isInstance(jwk)) {\n            return desiredType.cast(jwk);","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/impl/src/main/java/io/jsonwebtoken/impl/security/JwkConverter.java#L139-L175","documentation":"Thrown by JwkConverter.applyFrom when a JWK's kty member is a String but empty. RFC 7517 requires kty to be a meaningful key-type identifier; an empty string cannot identify a key type, so the JWK is rejected as malformed (MalformedKeyException).","triggerScenarios":"JWK JSON such as {\"kty\":\"\"} or {\"kty\":\"   \"} passed to JWK parsing/conversion.","commonSituations":"Placeholder values left in generated config; field stripped by a template engine; upstream key provider returning empty kty.","solutions":["Supply a valid kty value (\"EC\", \"RSA\", \"oct\", \"OKP\")","Trim/default handling in the code that generates or forwards JWK JSON","Validate the key JSON before passing it to the jjwt Jwks APIs"],"exampleFix":"// before\n{\"kty\":\"\", \"crv\":\"P-256\", \"x\":\"...\", \"y\":\"...\"}\n// after\n{\"kty\":\"EC\", \"crv\":\"P-256\", \"x\":\"...\", \"y\":\"...\"}","handlingStrategy":"validation","validationCode":"String kty = (String) jwkMap.get(\"kty\"); if (kty == null || kty.isBlank()) { throw new IllegalArgumentException(\"kty must be non-empty\"); }","typeGuard":"boolean hasTextKty(Map<String,?> m) { return m != null && m.get(\"kty\") instanceof String s && !s.isBlank(); }","tryCatchPattern":"try { jwk = parser.parse(json); } catch (MalformedKeyException e) { log.error(\"Empty kty: {}\", e.getMessage()); }","preventionTips":["Never emit placeholder empty strings for kty","Validate generated key documents with a schema check before use"],"tags":["jwt","jwk","validation","empty-value"],"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-14T05:17:10.506Z"}