{"record":{"id":"20e57a16286cc155","repo":"jwtk/jjwt","slug":"jwk-kty-value-cannot-be-null","errorCode":null,"errorMessage":"JWK kty value cannot be null.","messagePattern":"JWK kty value cannot be null\\.","errorType":"validation","errorClass":"io.jsonwebtoken.security.MalformedKeyException","httpStatus":null,"severity":"error","filePath":"impl/src/main/java/io/jsonwebtoken/impl/security/JwkConverter.java","lineNumber":148,"sourceCode":"            throw unexpectedIAE((Jwk<?>) o);\n        }\n        if (!(o instanceof Map)) {\n            String msg = \"JWK must be a Map<String,?> (JSON Object). Type found: \" + o.getClass().getName() + \".\";\n            throw new IllegalArgumentException(msg);\n        }\n        final Map<?, ?> map = Collections.immutable((Map<?, ?>) o);\n\n        Parameter<String> param = AbstractJwk.KTY;\n        // 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() + \".\";","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/impl/src/main/java/io/jsonwebtoken/impl/security/JwkConverter.java#L130-L166","documentation":"applyFrom checks the value of the mandatory 'kty' parameter for null after confirming the key exists. A JWK whose 'kty' member is present but JSON null is malformed, so MalformedKeyException is thrown.","triggerScenarios":"Parsing JWK JSON like {\"kty\": null, ...} or building a JWK from a map where kty maps to null.","commonSituations":"Deserialization frameworks or template-generated JSON that emit explicit nulls; partial key material filled in programmatically.","solutions":["Provide a non-null \"kty\" value such as \"RSA\", \"EC\", \"oct\", or \"OKP\"","Sanitize the JSON before parsing to remove null-valued fields","Log/inspect the source of the key data to find where the null originates"],"exampleFix":"// before\n{\"kty\": null, \"n\": \"...\", \"e\": \"AQAB\"}\n// after\n{\"kty\": \"RSA\", \"n\": \"...\", \"e\": \"AQAB\"}","handlingStrategy":"validation","validationCode":"Object kty = jwkMap.get(\"kty\"); if (kty == null) { throw new IllegalArgumentException(\"JWK 'kty' must not be null\"); }","typeGuard":"boolean hasNonNullKty(Map<String,?> m) { return m != null && m.get(\"kty\") != null; }","tryCatchPattern":"try { jwk = jwkParser.parse(map); } catch (MalformedKeyException e) { log.error(\"JWK rejected: {}\", e.getMessage()); }","preventionTips":["Strip null-valued members before passing JWK maps to jjwt","Fill kty programmatically when constructing keys in code"],"tags":["jwt","jwk","null","validation"],"backgroundTag":"missing-required-argument","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"}