{"record":{"id":"fba7b2b0d1cd43d2","repo":"apache/dubbo","slug":"class-null","errorCode":null,"errorMessage":"class == null","messagePattern":"class == null","errorType":"exception","errorClass":"NoSuchMethodException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/ClassUtils.java","lineNumber":348,"sourceCode":"                        || type == short.class\n                        || type == int.class\n                        || type == long.class\n                        || type == float.class\n                        || type == double.class) {\n                    def = \"0\";\n                } else {\n                    def = \"null\";\n                }\n                buf.append(def);\n            }\n        }\n        return method.getName() + \"(\" + buf + \")\";\n    }\n\n    public static Method searchMethod(Class<?> currentClass, String name, Class<?>[] parameterTypes)\n            throws NoSuchMethodException {\n        if (currentClass == null) {\n            throw new NoSuchMethodException(\"class == null\");\n        }\n        try {\n            return currentClass.getMethod(name, parameterTypes);\n        } catch (NoSuchMethodException e) {\n            for (Method method : currentClass.getMethods()) {\n                if (method.getName().equals(name)\n                        && parameterTypes.length == method.getParameterTypes().length\n                        && Modifier.isPublic(method.getModifiers())) {\n                    if (parameterTypes.length > 0) {\n                        Class<?>[] types = method.getParameterTypes();\n                        boolean match = true;\n                        for (int i = 0; i < parameterTypes.length; i++) {\n                            if (!types[i].isAssignableFrom(parameterTypes[i])) {\n                                match = false;\n                                break;\n                            }\n                        }\n                        if (!match) {","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/ClassUtils.java#L330-L366","documentation":"Thrown by ClassUtils.searchMethod when currentClass is null. The method searches for a public method by name and compatible parameter types, but it cannot operate without a class to search, so a null class is rejected up front.","triggerScenarios":"Calling ClassUtils.searchMethod(null, name, paramTypes), or a caller that resolves the class (e.g. via getClass() on a null object, or a type lookup that returned null) and forwards it without a null check.","commonSituations":"A reflection-based dispatch path received a null target type — e.g. a service reference whose interface class could not be loaded, or a method lookup on a null return type. Often a symptom of an upstream null rather than a direct call.","solutions":["Check that currentClass is non-null before calling searchMethod.","Trace back to where currentClass was obtained and ensure the type resolution cannot return null.","If the class legitimately may be absent, handle null upstream with an early return or clear error."],"exampleFix":"// before\nMethod m = ClassUtils.searchMethod(maybeNullClass, \"doWork\", types);\n// after\nif (maybeNullClass == null) throw new IllegalArgumentException(\"target class is null\");\nMethod m = ClassUtils.searchMethod(maybeNullClass, \"doWork\", types);","handlingStrategy":"validation","validationCode":"if (currentClass == null) {\n    throw new IllegalArgumentException(\"target class must not be null\");\n}\nMethod m = ClassUtils.searchMethod(currentClass, name, paramTypes);","typeGuard":"static boolean hasTargetClass(Class<?> c) {\n    return c != null;\n}","tryCatchPattern":"try {\n    Method m = ClassUtils.searchMethod(currentClass, name, paramTypes);\n} catch (NoSuchMethodException e) {\n    // currentClass was null or method not found; fix upstream null\n}","preventionTips":["Null-check the class before calling searchMethod.","Ensure upstream type resolution never returns null.","Add defensive checks where service interface classes are loaded dynamically."],"tags":["reflection","utils","validation","null-check"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}