apache/incubator-seata · error · NoSuchMethodException
static method not found: {}
Error message
static method not found: {} What it means
ReflectionUtil.invokeStaticMethod resolves the named method via getMethod and then requires it to be static. If the method exists but is an instance method (or resolution matched a non-static overload), it throws NoSuchMethodException("static method not found: " + methodToString(...)) — the message embeds the full class.method(parameters) signature. Note: a truly missing name throws NoSuchMethodException from getMethod itself instead.
Source
Thrown at common/src/main/java/org/apache/seata/common/util/ReflectionUtil.java:669
* @param args the args
* @return the result of the static method
* @throws IllegalArgumentException if {@code targetClass} is {@code null}
* @throws NullPointerException if {@code methodName} is {@code null}
* @throws NoSuchMethodException the no such method exception
* @throws InvocationTargetException if the underlying method throws an exception.
* @throws SecurityException the security exception
*/
public static Object invokeStaticMethod(
Class<?> targetClass, String staticMethodName, Class<?>[] parameterTypes, Object... args)
throws IllegalArgumentException, NoSuchMethodException, InvocationTargetException, SecurityException {
if (targetClass == null) {
throw new IllegalArgumentException("targetClass must be not null");
}
// get method
Method staticMethod = getMethod(targetClass, staticMethodName, parameterTypes);
if (!Modifier.isStatic(staticMethod.getModifiers())) {
throw new NoSuchMethodException(
"static method not found: " + methodToString(targetClass, staticMethodName, parameterTypes));
}
return invokeStaticMethod(staticMethod, args);
}
/**
* invoke static Method
*
* @param targetClass the target class
* @param staticMethodName the static method name
* @return the result of the static method
* @throws IllegalArgumentException if {@code targetClass} is {@code null}
* @throws NullPointerException if {@code methodName} is {@code null}
* @throws NoSuchMethodException the no such method exception
* @throws InvocationTargetException if the underlying method throws an exception.
* @throws SecurityException the security exception
*/View on GitHub (pinned to e01f97c6db)
Solutions
- Add 'static' to the target method declaration, or invoke it on an instance via the instance-method variant of ReflectionUtil
- Verify the exact method name, parameter types, and staticness with javap or IDE inspection before the reflective call
- Pin/align dependency versions so reflective targets match the compiled signatures
Example fix
// before
class SerializerHolder { Object create(Class<?> c) { ... } } // instance method
ReflectionUtil.invokeStaticMethod(SerializerHolder.class, "create", new Class[]{Class.class}); // throws
// after
class SerializerHolder { static Object create(Class<?> c) { ... } }
ReflectionUtil.invokeStaticMethod(SerializerHolder.class, "create", new Class[]{Class.class}); Defensive patterns
Strategy: validation
Validate before calling
Method m = targetClass.getMethod("create", paramTypes);
if (!Modifier.isStatic(m.getModifiers())) throw new IllegalStateException("create is not static on " + targetClass);
ReflectionUtil.invokeStaticMethod(targetClass, "create", paramTypes); Type guard
static boolean isStaticMethod(Class<?> c, String name, Class<?>[] pt) throws NoSuchMethodException { return Modifier.isStatic(c.getMethod(name, pt).getModifiers()); } Try / catch
try { ReflectionUtil.invokeStaticMethod(c, "create", pt); } catch (NoSuchMethodException e) { throw new ConfigurationException("expected static factory missing: " + e.getMessage(), e); } Prevention
- Verify staticness with reflection (Modifier.isStatic) before invoking
- Pin dependency versions whose reflective targets you rely on
- Write a startup self-test for each reflectively invoked factory method
When it happens
Trigger: Calling invokeStaticMethod(targetClass, "someMethod", parameterTypes, ...) where someMethod is declared without 'static' in the target class — e.g. invoking a factory method after someone removed the static modifier, or passing an interface/instance utility class whose methods are all instance-level.
Common situations: Upgrading a dependency whose API changed a static factory to an instance method (or vice versa); copy-pasted method names; refactors that made a helper non-static without updating reflective callers such as seata serializer/compressor factories.
Related errors
- targetClass must be not null
- Extension instance(definition: {}, class: {}) could not be
- Never BEGIN on a RELOADED GlobalTransaction.
AI-assisted analysis of apache/incubator-seata@e01f97c6db (2026-08-14).
Data as JSON: /api/errors/cb475af31bbba74d.
Report an issue: GitHub.