{"record":{"id":"b0b6aa8950845309","repo":"alibaba/Sentinel","slug":"null-method","errorCode":null,"errorMessage":"Null method","messagePattern":"Null method","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sentinel-core/src/main/java/com/alibaba/csp/sentinel/util/MethodUtil.java","lineNumber":41,"sourceCode":" * Util class for processing {@link Method}.\n *\n * @author youji.zj\n */\npublic final class MethodUtil {\n\n    private static final Map<Method, String> methodNameMap = new ConcurrentHashMap<Method, String>();\n\n    private static final Object LOCK = new Object();\n\n    /**\n     * Parse and resolve the method name, then cache to the map.\n     *\n     * @param method method instance\n     * @return resolved method name\n     */\n    public static String resolveMethodName(Method method) {\n        if (method == null) {\n            throw new IllegalArgumentException(\"Null method\");\n        }\n        String methodName = methodNameMap.get(method);\n        if (methodName == null) {\n            synchronized (LOCK) {\n                methodName = methodNameMap.get(method);\n                if (methodName == null) {\n                    StringBuilder sb = new StringBuilder();\n\n                    String className = method.getDeclaringClass().getName();\n                    String name = method.getName();\n                    Class<?>[] params = method.getParameterTypes();\n                    sb.append(className).append(\":\").append(name);\n                    sb.append(\"(\");\n\n                    int paramPos = 0;\n                    for (Class<?> clazz : params) {\n                        sb.append(clazz.getCanonicalName());\n                        if (++paramPos < params.length) {","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/alibaba/Sentinel/blob/a3f40ba8e900c8489bd520274739f17235a7721c/sentinel-core/src/main/java/com/alibaba/csp/sentinel/util/MethodUtil.java#L23-L59","documentation":"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.","triggerScenarios":"MethodUtil.resolveMethodName(null), or passing a Method reference that came from a failed reflective lookup (Class.getMethod wrapped so null is returned on failure).","commonSituations":"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.","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."],"exampleFix":"// before\nMethod m = clazz.getMethod(\"handle\"); // may throw / be null after catch\nString name = MethodUtil.resolveMethodName(m);\n\n// after\nMethod m = clazz.getMethod(\"handle\");\nString name = (m != null)\n    ? MethodUtil.resolveMethodName(m)\n    : \"handle-fallback-resource\";","handlingStrategy":"type-guard","validationCode":"if (method == null) {\n    throw new IllegalStateException(\"method lookup failed for resource \" + resourceName);\n}\nString mn = MethodUtil.resolveMethodName(method);","typeGuard":"boolean isResolvableMethod(Method m) {\n    return m != null;\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["sentinel","reflection","method-resource","null-check"],"backgroundTag":null,"analyzedSha":"a3f40ba8e900c8489bd520274739f17235a7721c","analyzedAt":"2026-08-14T11:10:30.678Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}