apache/incubator-seata · error · IllegalArgumentException
targetClass must be not null
Error message
targetClass must be not null
What it means
ReflectionUtil.invokeStaticMethod invokes a static method by name on a target class. It first asserts targetClass is non-null and throws IllegalArgumentException("targetClass must be not null") otherwise — a programming-error guard so callers fail fast when the Class reference (often from Class.forName or config) is missing rather than NPE-ing later.
Source
Thrown at common/src/main/java/org/apache/seata/common/util/ReflectionUtil.java:663
/**
* invoke static Method
*
* @param targetClass the target class
* @param staticMethodName the static method name
* @param parameterTypes the parameter types
* @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 methodView on GitHub (pinned to e01f97c6db)
Solutions
- Fix the upstream class lookup so targetClass is never null — check Class.forName inputs and handle ClassNotFoundException separately
- Null-check targetClass before the call and raise a descriptive error naming the missing class
- Validate configurable class names at startup (exists on classpath) rather than at first use
Example fix
// before
Object r = ReflectionUtil.invokeStaticMethod(clazz, "init", null); // clazz == null -> throws
// after
if (clazz == null) throw new IllegalStateException("class not loaded: " + className);
Object r = ReflectionUtil.invokeStaticMethod(clazz, "init", null); Defensive patterns
Strategy: validation
Validate before calling
if (targetClass == null) throw new IllegalStateException("target class not loaded: " + className);
ReflectionUtil.invokeStaticMethod(targetClass, "init", paramTypes); Try / catch
try { ReflectionUtil.invokeStaticMethod(clazz, m, pt); } catch (IllegalArgumentException e) { throw new ConfigurationException("class missing for reflective call", e); } Prevention
- Resolve classes once at startup and fail fast if missing
- Validate configurable class names against the classpath during boot
- Never pass a possibly-null Class into reflection utilities
When it happens
Trigger: Calling ReflectionUtil.invokeStaticMethod(null, "methodName", paramTypes, args) — typically because Class.forName(className) failed upstream and returned/propagated null, or a configurable class name was blank so the lookup produced null.
Common situations: Config-driven class names (e.g. serializer or compressor factory classes in seata config) that are misspelled or absent, leaving a null Class passed into reflection-based instantiation; refactors that changed a class constant to an optional value.
Related errors
- static method not found: {}
- Extension instance(definition: {}, class: {}) could not be
- Never BEGIN on a RELOADED GlobalTransaction.
- bytes is null
- bytes is null
AI-assisted analysis of apache/incubator-seata@e01f97c6db (2026-08-14).
Data as JSON: /api/errors/e412213f2685e55b.
Report an issue: GitHub.