{"record":{"id":"dab5b7c51c843250","repo":"jwtk/jjwt","slug":"unable-to-invoke-class-method-clazzname-metho","errorCode":null,"errorMessage":"Unable to invoke class method ${clazzName}#${methodName}. Ensure the necessary implementation is in the runtime classpath.","messagePattern":"Unable to invoke class method (.+?)#(.+?)\\. Ensure the necessary implementation is in the runtime classpath\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/io/jsonwebtoken/lang/Classes.java","lineNumber":329,"sourceCode":"     * @param args       the actual runtime arguments to use when invoking the method\n     * @param <T>        the type of object expected to be returned from the method\n     * @return the result returned by the invoked method.\n     * @since 0.12.0\n     */\n    @SuppressWarnings(\"unchecked\")\n    public static <T> T invokeStatic(Class<?> clazz, String methodName, Class<?>[] argTypes, Object... args) {\n        try {\n            Method method = clazz.getDeclaredMethod(methodName, argTypes);\n            method.setAccessible(true);\n            return (T) method.invoke(null, args);\n        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {\n            Throwable cause = e.getCause();\n            if (cause instanceof RuntimeException) {\n                throw ((RuntimeException) cause); //propagate\n            }\n            String msg = \"Unable to invoke class method \" + clazz.getName() + \"#\" + methodName +\n                    \". Ensure the necessary implementation is in the runtime classpath.\";\n            throw new IllegalStateException(msg, e);\n        }\n    }\n\n    /**\n     * Returns the {@code instance}'s named (declared) field value.\n     *\n     * @param instance  the instance with the internal field\n     * @param fieldName the name of the field to inspect\n     * @param fieldType the type of field to inspect\n     * @param <T>       field instance value type\n     * @return the field value\n     */\n    public static <T> T getFieldValue(Object instance, String fieldName, Class<T> fieldType) {\n        if (instance == null) return null;\n        try {\n            Field field = instance.getClass().getDeclaredField(fieldName);\n            field.setAccessible(true);\n            Object o = field.get(instance);","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/api/src/main/java/io/jsonwebtoken/lang/Classes.java#L311-L347","documentation":"IllegalStateException thrown by the Class-based io.jsonwebtoken.lang.Classes.invokeStatic when the reflected static method invocation fails. If the underlying cause is a RuntimeException it is rethrown directly; otherwise the message includes the class and method names with a classpath hint.","triggerScenarios":"invokeStatic(clazz, methodName, argTypes, args) where the method throws a checked/non-runtime exception, or method resolution fails after the Class was loaded (e.g. NoSuchMethodException due to argTypes mismatch).","commonSituations":"Static method's internal code throwing a checked exception; passing argTypes that don't match the declared method; class loaded but from a jar version where the method signature changed.","solutions":["Inspect the cause to see whether the target method threw or resolution failed","Correct the argTypes/args to match the exact static method signature","Ensure the classpath holds the intended jar version with that method","Catch the propagated RuntimeException separately, as it is rethrown unwrapped"],"exampleFix":"// before\nObject r = Classes.invokeStatic(Impl.class, \"create\", new Class[]{String.class}, new Object[]{42}); // wrong arg type\n// after\nObject r = Classes.invokeStatic(Impl.class, \"create\", new Class[]{Integer.class}, new Object[]{42});","handlingStrategy":"try-catch","validationCode":"try {\n    clazz.getMethod(methodName, argTypes);\n} catch (NoSuchMethodException e) {\n    throw new IllegalArgumentException(\"No static method \" + methodName + \" with those arg types on \" + clazz);\n}","typeGuard":null,"tryCatchPattern":"try {\n    return Classes.invokeStatic(clazz, methodName, argTypes, args);\n} catch (IllegalStateException e) {\n    // non-runtime exceptions land here wrapped; RuntimeExceptions are rethrown directly by the library\n    throw e;\n} catch (RuntimeException e) {\n    // method's own runtime exception propagated unwrapped\n    throw e;\n}","preventionTips":["Verify argTypes exactly match the declared parameter types","Pin library versions so method signatures do not drift","Handle the target method's runtime exceptions separately since they propagate unwrapped"],"tags":["reflection","static-method","classpath"],"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"}