jwtk/jjwt · error · IllegalStateException
Unable to invoke class method ${fqcn}#${methodName}. Ensure
Error message
Unable to invoke class method ${fqcn}#${methodName}. Ensure the necessary implementation is in the runtime classpath. What it means
IllegalStateException thrown by the varargs-entry io.jsonwebtoken.lang.Classes.invokeStatic(String fqcn, ...) when it cannot load the class or dispatch to the static method. It delegates to Classes.forName and the Class-based invokeStatic, wrapping any failure with a classpath-oriented hint. This means reflection-based method lookup/invocation failed.
Source
Thrown at api/src/main/java/io/jsonwebtoken/lang/Classes.java:300
* Invokes the fully qualified class name's method named {@code methodName} with parameters of type {@code argTypes}
* using the {@code args} as the method arguments.
*
* @param fqcn fully qualified class name to locate
* @param methodName name of the method to invoke on the class
* @param argTypes the method argument types supported by the {@code methodName} method
* @param args the runtime arguments to use when invoking the located class method
* @param <T> the expected type of the object returned from the invoked method.
* @return the result returned by the invoked method
* @since 0.10.0
*/
public static <T> T invokeStatic(String fqcn, String methodName, Class<?>[] argTypes, Object... args) {
try {
Class<?> clazz = Classes.forName(fqcn);
return invokeStatic(clazz, methodName, argTypes, args);
} catch (Exception e) {
String msg = "Unable to invoke class method " + fqcn + "#" + methodName + ". Ensure the necessary " +
"implementation is in the runtime classpath.";
throw new IllegalStateException(msg, e);
}
}
/**
* Invokes the {@code clazz}'s matching static method (named {@code methodName} with exact argument types
* of {@code argTypes}) with the given {@code args} arguments, and returns the method return value.
*
* @param clazz the class to invoke
* @param methodName the name of the static method on {@code clazz} to invoke
* @param argTypes the types of the arguments accepted by the method
* @param args the actual runtime arguments to use when invoking the method
* @param <T> the type of object expected to be returned from the method
* @return the result returned by the invoked method.
* @since 0.12.0
*/
@SuppressWarnings("unchecked")
public static <T> T invokeStatic(Class<?> clazz, String methodName, Class<?>[] argTypes, Object... args) {
try {View on GitHub (pinned to fb71496164)
Solutions
- Ensure the jar containing the class (often jjwt-impl) is on the runtime classpath
- Verify fqcn, methodName, and argTypes exactly match an existing public static method
- Check the cause exception: NoClassDefFoundError/ClassNotFoundException means classpath; NoSuchMethodException means signature mismatch
- Align library versions if the class moved between jjwt versions
Example fix
// before
Object r = Classes.invokeStatic("io.jsonwebtoken.impl.crypto.DefaultJwtSigner", "sign", new Class[0], new Object[0]); // class absent
// after
// add jjwt-impl to dependencies, then call typed APIs instead of reflection:
JwtParser p = Jwts.parserBuilder().build(); Defensive patterns
Strategy: try-catch
Validate before calling
if (!Classes.isAvailable(fqcn)) {
throw new IllegalStateException("Class " + fqcn + " missing — check runtime classpath");
} Try / catch
try {
return Classes.invokeStatic(fqcn, methodName, argTypes, args);
} catch (IllegalStateException e) {
if (e.getCause() instanceof ClassNotFoundException) {
throw new IllegalStateException("Missing jar for " + fqcn + " — check classpath", e);
}
throw e;
} Prevention
- Prefer typed public APIs over reflective invokeStatic
- Keep jjwt module versions aligned to avoid renamed classes
- Log e.getCause() to distinguish classpath vs signature problems
When it happens
Trigger: Classes.invokeStatic(fqcn, methodName, argTypes, args) where fqcn is not on the classpath (forName throws), the static method does not exist with those exact argument types, or the invoked method itself throws an exception.
Common situations: Missing jjwt-impl jar so implementation classes cannot be loaded; renamed/moved classes across jjwt versions; wrong method name or argument types passed programmatically.
Related errors
- Unable to invoke class method ${clazzName}#${methodName}. En
- Unable to load class named [${fqcn}] from the thread context
- Class method parameter cannot be null.
- Unable to instantiate class [${clazzName}]
- Unable to instantiate instance with constructor [${ctor}]
AI-assisted analysis of jwtk/jjwt@fb71496164 (2026-09-09).
Data as JSON: /api/errors/38c16ea16c88835d.
Report an issue: GitHub.