{"record":{"id":"5d4cefee290d1ffa","repo":"jwtk/jjwt","slug":"unsupported-jwkcontext","errorCode":null,"errorMessage":"Unsupported JwkContext.","messagePattern":"Unsupported JwkContext\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/src/main/java/io/jsonwebtoken/impl/security/AbstractFamilyJwkFactory.java","lineNumber":105,"sourceCode":"            public T apply(KeyFactory instance) {\n                try {\n                    return fn.apply(instance);\n                } catch (KeyException keyException) {\n                    throw keyException; // propagate\n                } catch (Exception e) {\n                    String msg = \"Unable to create \" + type.getSimpleName() + \" from JWK \" + ctx + \": \" + e.getMessage();\n                    throw new InvalidKeyException(msg, e);\n                }\n            }\n        });\n    }\n\n    @Override\n    public final J createJwk(JwkContext<K> ctx) {\n        Assert.notNull(ctx, \"JwkContext argument cannot be null.\");\n        if (!supports(ctx)) { //should be asserted by caller, but assert just in case:\n            String msg = \"Unsupported JwkContext.\";\n            throw new IllegalArgumentException(msg);\n        }\n        K key = ctx.getKey();\n        if (key != null) {\n            ctx.setType(this.ktyValue);\n            return createJwkFromKey(ctx);\n        } else {\n            return createJwkFromValues(ctx);\n        }\n    }\n\n    //when called, ctx.getKey() is guaranteed to be non-null\n    protected abstract J createJwkFromKey(JwkContext<K> ctx);\n\n    //when called ctx.getType() is guaranteed to equal this.ktyValue\n    protected abstract J createJwkFromValues(JwkContext<K> ctx);\n}\n","sourceCodeStart":87,"sourceCodeEnd":122,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/impl/src/main/java/io/jsonwebtoken/impl/security/AbstractFamilyJwkFactory.java#L87-L122","documentation":"createJwk asserts the JwkContext passed in is supported by this factory (supports(ctx) returned true), throwing IllegalArgumentException otherwise. Normally a dispatcher selects the right factory, so this guards against programmatic misuse of the internal API.","triggerScenarios":"Directly instantiating a concrete family JwkFactory and calling createJwk with a context whose key type ('kty') does not match the factory (e.g. passing an RSA context to an EC factory), or a null-keyed context of the wrong type.","commonSituations":"Custom JWK factory pipelines; unit tests calling factories directly instead of through Jwks.builder(); custom JwkFactory implementations delegating incorrectly.","solutions":["Create JWKs via Jwks.builder() so the correct factory is chosen automatically.","Ensure the JwkContext key type matches the factory you invoke (check ctx.getKty()).","Call factory.supports(ctx) before createJwk in custom dispatch code.","Wrap the call in try-catch for IllegalArgumentException if inputs are untrusted."],"exampleFix":"// before\nEccJwkFactory f = new EccJwkFactory();\nf.createJwk(rsaContext);\n// after\nif (f.supports(ctx)) { f.createJwk(ctx); } else { Jwks.builder().setContext(ctx).build(); }","handlingStrategy":"validation","validationCode":"if (!factory.supports(ctx)) { throw new IllegalArgumentException(\"kty \" + ctx.getKty() + \" not supported by this factory\"); }","typeGuard":null,"tryCatchPattern":"try { return factory.createJwk(ctx); }\ncatch (IllegalArgumentException e) { return dispatchToCorrectFactory(ctx); }","preventionTips":["Build JWKs via Jwks.builder(), not raw factories.","Check supports(ctx) before direct factory calls.","Keep ctx.getKty() consistent with the factory family."],"tags":["jwk","illegal-argument","factory","jjwt"],"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"}