apache/dubbo · error · NoSuchMethodException
class == null
Error message
class == null
What it means
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.
Source
Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/ClassUtils.java:348
|| type == short.class
|| type == int.class
|| type == long.class
|| type == float.class
|| type == double.class) {
def = "0";
} else {
def = "null";
}
buf.append(def);
}
}
return method.getName() + "(" + buf + ")";
}
public static Method searchMethod(Class<?> currentClass, String name, Class<?>[] parameterTypes)
throws NoSuchMethodException {
if (currentClass == null) {
throw new NoSuchMethodException("class == null");
}
try {
return currentClass.getMethod(name, parameterTypes);
} catch (NoSuchMethodException e) {
for (Method method : currentClass.getMethods()) {
if (method.getName().equals(name)
&& parameterTypes.length == method.getParameterTypes().length
&& Modifier.isPublic(method.getModifiers())) {
if (parameterTypes.length > 0) {
Class<?>[] types = method.getParameterTypes();
boolean match = true;
for (int i = 0; i < parameterTypes.length; i++) {
if (!types[i].isAssignableFrom(parameterTypes[i])) {
match = false;
break;
}
}
if (!match) {View on GitHub (pinned to 3a3043227f)
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.
Example fix
// before
Method m = ClassUtils.searchMethod(maybeNullClass, "doWork", types);
// after
if (maybeNullClass == null) throw new IllegalArgumentException("target class is null");
Method m = ClassUtils.searchMethod(maybeNullClass, "doWork", types); Defensive patterns
Strategy: validation
Validate before calling
if (currentClass == null) {
throw new IllegalArgumentException("target class must not be null");
}
Method m = ClassUtils.searchMethod(currentClass, name, paramTypes); Type guard
static boolean hasTargetClass(Class<?> c) {
return c != null;
} Try / catch
try {
Method m = ClassUtils.searchMethod(currentClass, name, paramTypes);
} catch (NoSuchMethodException e) {
// currentClass was null or method not found; fix upstream null
} Prevention
- Null-check the class before calling searchMethod.
- Ensure upstream type resolution never returns null.
- Add defensive checks where service interface classes are loaded dynamically.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Can not create wrapper for primitive type: {}
- pns.length != pvs.length
- task
- object is null
- Invalid configurator rule, please specify at least one param
AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14).
Data as JSON: /api/errors/fba7b2b0d1cd43d2.
Report an issue: GitHub.