alibaba/Sentinel · error · IllegalArgumentException
Null method
Error message
Null method
What it means
MethodUtil.resolveMethodName(Method) builds and caches the 'className:name:paramTypes' signature string used for method-level (Sphu.entry with Method) resource names. A null Method has no declaring class or name, so it throws IllegalArgumentException immediately.
Source
Thrown at sentinel-core/src/main/java/com/alibaba/csp/sentinel/util/MethodUtil.java:41
* Util class for processing {@link Method}.
*
* @author youji.zj
*/
public final class MethodUtil {
private static final Map<Method, String> methodNameMap = new ConcurrentHashMap<Method, String>();
private static final Object LOCK = new Object();
/**
* Parse and resolve the method name, then cache to the map.
*
* @param method method instance
* @return resolved method name
*/
public static String resolveMethodName(Method method) {
if (method == null) {
throw new IllegalArgumentException("Null method");
}
String methodName = methodNameMap.get(method);
if (methodName == null) {
synchronized (LOCK) {
methodName = methodNameMap.get(method);
if (methodName == null) {
StringBuilder sb = new StringBuilder();
String className = method.getDeclaringClass().getName();
String name = method.getName();
Class<?>[] params = method.getParameterTypes();
sb.append(className).append(":").append(name);
sb.append("(");
int paramPos = 0;
for (Class<?> clazz : params) {
sb.append(clazz.getCanonicalName());
if (++paramPos < params.length) {View on GitHub (pinned to a3f40ba8e9)
Solutions
- Ensure the Method object passed in is non-null; log it before calling resolveMethodName.
- If it comes from reflection, check why the lookup returned null (wrong method name, params mismatch, accessibility) and fix the lookup.
- Guard: if (method == null) fall back to a string resource name instead of calling resolveMethodName.
Example fix
// before
Method m = clazz.getMethod("handle"); // may throw / be null after catch
String name = MethodUtil.resolveMethodName(m);
// after
Method m = clazz.getMethod("handle");
String name = (m != null)
? MethodUtil.resolveMethodName(m)
: "handle-fallback-resource"; Defensive patterns
Strategy: type-guard
Validate before calling
if (method == null) {
throw new IllegalStateException("method lookup failed for resource " + resourceName);
}
String mn = MethodUtil.resolveMethodName(method); Type guard
boolean isResolvableMethod(Method m) {
return m != null;
} Prevention
- Never swallow NoSuchMethodException into a null return; propagate or fail loudly.
- In annotation/AOP scenarios, resolve the Method once at startup and validate non-null before first request.
When it happens
Trigger: MethodUtil.resolveMethodName(null), or passing a Method reference that came from a failed reflective lookup (Class.getMethod wrapped so null is returned on failure).
Common situations: Method-based resource definition (MethodResourceUtil / SentinelResourceAspect method entry) where the target method annotation lookup returned null — e.g. @SentinelResource on an overloaded/inherited method not found reflectively, or AOP proxies returning null from a custom method resolver.
Related errors
- ${name} is null
- Invalid map instance
- Request cannot be null
- Bad class metadata
- charset is not allowed to be null
AI-assisted analysis of alibaba/Sentinel@a3f40ba8e9 (2026-08-14).
Data as JSON: /api/errors/b0b6aa8950845309.
Report an issue: GitHub.