{"record":{"id":"b0715ebe43ad55b1","repo":"jwtk/jjwt","slug":"nofamily-key-kty","errorCode":null,"errorMessage":"noFamily(key, kty)","messagePattern":"noFamily\\(key, kty\\)","errorType":"exception","errorClass":"UnsupportedKeyException","httpStatus":null,"severity":"error","filePath":"impl/src/main/java/io/jsonwebtoken/impl/security/DispatchingJwkFactory.java","lineNumber":71,"sourceCode":"        this.factories = new ArrayList<>(factories.size());\n        for (FamilyJwkFactory<?, ?> factory : factories) {\n            Assert.hasText(factory.getId(), \"FamilyJwkFactory.getFactoryId() cannot return null or empty.\");\n            this.factories.add((FamilyJwkFactory<Key, ?>) factory);\n        }\n    }\n\n    @Override\n    public JwkContext<Key> newContext(JwkContext<?> src, Key key) {\n        Assert.notNull(src, \"JwkContext cannot be null.\");\n        String kty = src.getType();\n        assertKeyOrKeyType(key, kty);\n        for (FamilyJwkFactory<Key, ?> factory : this.factories) {\n            if (factory.supports(key) || factory.supports(src)) {\n                JwkContext<Key> ctx = factory.newContext(src, key);\n                return Assert.notNull(ctx, \"FamilyJwkFactory implementation cannot return null JwkContexts.\");\n            }\n        }\n        throw noFamily(key, kty);\n    }\n\n    private static void assertKeyOrKeyType(Key key, String kty) {\n        if (key == null && !Strings.hasText(kty)) {\n            String msg = \"Either a Key instance or a \" + AbstractJwk.KTY + \" value is required to create a JWK.\";\n            throw new InvalidKeyException(msg);\n        }\n    }\n\n    @Override\n    public Jwk<Key> createJwk(JwkContext<Key> ctx) {\n\n        Assert.notNull(ctx, \"JwkContext cannot be null.\");\n\n        final Key key = ctx.getKey();\n        final String kty = Strings.clean(ctx.getType());\n        assertKeyOrKeyType(key, kty);\n","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/impl/src/main/java/io/jsonwebtoken/impl/security/DispatchingJwkFactory.java#L53-L89","documentation":"Thrown as UnsupportedKeyException when DispatchingJwkFactory.newContext cannot find any registered FamilyJwkFactory whose supports() matches the given Key or source JWK map. In other words, neither the key's Java type nor the JWK 'kty' value maps to a key family (RSA, EC, octet, OKP) the library knows.","triggerScenarios":"Creating a JWK context from a Key of unsupported type (e.g. DSA) or from a JWK map whose 'kty' is unrecognized (typo like 'rsa ' or custom values like 'RSA-PSS'), via JwkBuilder or Jwk parsing.","commonSituations":"Importing third-party JWK Sets with non-standard kty values; hand-editing JWK JSON; passing keys from custom crypto providers; case mistakes in kty (JWK kty values are case-sensitive).","solutions":["Correct the 'kty' value to a standard one: RSA, EC, oct, or OKP (exact, case-sensitive).","Use a supported Key type: RSAPublicKey, RSAPrivateKey, ECPublicKey, ECPrivateKey, or SecretKey.","Register additional family factories if supporting a custom key type is required (extend FamilyJwkFactory and configure the JwkFactory).","Catch UnsupportedKeyException during JWK set import and skip/log the offending entry."],"exampleFix":"// before\n{ \"kty\": \"rsa\", \"n\": \"...\", \"e\": \"AQAB\" }   // lowercase kty unsupported\n// after\n{ \"kty\": \"RSA\", \"n\": \"...\", \"e\": \"AQAB\" }","handlingStrategy":"validation","validationCode":"// validate kty before importing a JWK\nString kty = (String) jwkMap.get(\"kty\");\nif (!Set.of(\"RSA\",\"EC\",\"oct\",\"OKP\").contains(kty))\n    throw new InvalidJwkException(\"Unsupported kty: \" + kty);","typeGuard":"boolean knownKty = Set.of(\"RSA\",\"EC\",\"oct\",\"OKP\").contains(jwkMap.get(\"kty\"));","tryCatchPattern":"try {\n    return Jwts.SIG.parser().parse(jwkJson);\n} catch (UnsupportedKeyException e) {\n    log.warn(\"Skipping JWK with unsupported family\", e);\n    return null;\n}","preventionTips":["kty values are case-sensitive — always use exact spelling","Sanitize third-party JWK Sets on import","Only use supported Key types for JWK creation","Register custom FamilyJwkFactory implementations for non-standard key types"],"tags":["jwt","jwk","kty","unsupported-key"],"backgroundTag":"unsupported-key-type","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"}