apache/hadoop · error · NoSuchMethodException
Cannot find method: {name}
Error message
Cannot find method: {name} What it means
DynMethods.Builder accumulates candidate reflective lookups (impl/hiddenImpl) and keeps the first that resolves. buildChecked() throws NoSuchMethodException('Cannot find method: <name>') when every candidate failed: either no target class declared a matching method, or the argument Class list did not match exactly. This is the machinery behind Hadoop cross-JDK shims (e.g. SignalUtil binding sun.misc.Signal.handle), so the usual root cause is a JDK/library version without that method or an exact-signature mismatch (getDeclaredMethod does no widening or boxing).
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/dynamic/DynMethods.java:463
* @param argClasses argument classes for the method
* @return this Builder for method chaining
*/
public Builder hiddenImpl(Class<?> targetClass, Class<?>... argClasses) {
hiddenImpl(targetClass, name, argClasses);
return this;
}
/**
* Returns the first valid implementation as a UnboundMethod or throws a
* NoSuchMethodException if there is none.
* @return a {@link UnboundMethod} with a valid implementation
* @throws NoSuchMethodException if no implementation was found
*/
public UnboundMethod buildChecked() throws NoSuchMethodException {
if (method != null) {
return method;
} else {
throw new NoSuchMethodException("Cannot find method: " + name);
}
}
/**
* Returns the first valid implementation as a UnboundMethod or throws a
* RuntimeError if there is none.
* @return a {@link UnboundMethod} with a valid implementation
* @throws RuntimeException if no implementation was found
*/
public UnboundMethod build() {
if (method != null) {
return method;
} else {
throw new RuntimeException("Cannot find method: " + name);
}
}
/**View on GitHub (pinned to 2add963021)
Solutions
- Enable debug logging for org.apache.hadoop.util.dynamic - every failed candidate logs 'failed to load method ... from class ...' with the underlying cause
- Check parameter types exactly: int vs Integer, no widening, no varargs expansion in getDeclaredMethod
- Add another .impl(...) candidate matching the version you actually run, or register an .orNoop() fallback
- Confirm only one version of the target class is on the classpath (dependency:tree, or log cls.getProtectionDomain().getCodeSource())
Example fix
// before: single candidate; throws NoSuchMethodException on JDKs without it
DynMethods.UnboundMethod m = new DynMethods.Builder("handle")
.impl(signalClass, handlerClass).buildChecked();
// after: cover the alternate signature and degrade to no-op
DynMethods.UnboundMethod m = new DynMethods.Builder("handle")
.impl(signalClass, handlerClass)
.orNoop()
.build(); Defensive patterns
Strategy: try-catch
Type guard
static boolean hasMethod(Class<?> target, String name, Class<?>... args) {
try {
target.getDeclaredMethod(name, args);
return true;
} catch (NoSuchMethodException e) {
return false;
}
} Try / catch
DynMethods.UnboundMethod m;
try {
m = new DynMethods.Builder("handle").impl(cls, handlerClass).buildChecked();
} catch (NoSuchMethodException e) {
LOG.warn("optional binding 'handle' unavailable on this runtime; degrading", e);
m = null;
} Prevention
- Register multiple impl/hiddenImpl candidates covering the JDK/library versions you support, ending with .orNoop() when absence is tolerable
- Match parameter types exactly (int vs Integer) - getDeclaredMethod does not widen or box
- Keep one version of the probed class on the classpath; log getCodeSource() when diagnosing
When it happens
Trigger: new DynMethods.Builder("handle").impl(signalClass, SignalHandler.class).buildChecked() on a JDK where sun.misc.Signal moved or lost that overload; hiddenImpl("com.acme.Shaded", ...) loading a different shaded version that lacks the method; passing Integer.class where the method declares int; tests running against stubs without the method.
Common situations: Running on a newer/older JDK than the shim covers; dependency upgrades that rename or re-signature methods; two versions of the target class on the classpath; shaded JARs relocating classes.
Related errors
- No KeyProviderFactory for ${uri} in ${KEY_PROVIDER_PATH}
- Cannot initialize the class: {clazz}
- Unbound ${method}
- Error creating plugin: {}
- Error in configuring object
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/3ccecfdcb5b5f060.
Report an issue: GitHub.