{"record":{"id":"3ccecfdcb5b5f060","repo":"apache/hadoop","slug":"cannot-find-method-name","errorCode":null,"errorMessage":"Cannot find method: {name}","messagePattern":"Cannot find method: (.+?)","errorType":"exception","errorClass":"NoSuchMethodException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/dynamic/DynMethods.java","lineNumber":463,"sourceCode":"     * @param argClasses argument classes for the method\n     * @return this Builder for method chaining\n     */\n    public Builder hiddenImpl(Class<?> targetClass, Class<?>... argClasses) {\n      hiddenImpl(targetClass, name, argClasses);\n      return this;\n    }\n\n    /**\n     * Returns the first valid implementation as a UnboundMethod or throws a\n     * NoSuchMethodException if there is none.\n     * @return a {@link UnboundMethod} with a valid implementation\n     * @throws NoSuchMethodException if no implementation was found\n     */\n    public UnboundMethod buildChecked() throws NoSuchMethodException {\n      if (method != null) {\n        return method;\n      } else {\n        throw new NoSuchMethodException(\"Cannot find method: \" + name);\n      }\n    }\n\n    /**\n     * Returns the first valid implementation as a UnboundMethod or throws a\n     * RuntimeError if there is none.\n     * @return a {@link UnboundMethod} with a valid implementation\n     * @throws RuntimeException if no implementation was found\n     */\n    public UnboundMethod build() {\n      if (method != null) {\n        return method;\n      } else {\n        throw new RuntimeException(\"Cannot find method: \" + name);\n      }\n    }\n\n    /**","sourceCodeStart":445,"sourceCodeEnd":481,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/dynamic/DynMethods.java#L445-L481","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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())"],"exampleFix":"// before: single candidate; throws NoSuchMethodException on JDKs without it\nDynMethods.UnboundMethod m = new DynMethods.Builder(\"handle\")\n    .impl(signalClass, handlerClass).buildChecked();\n\n// after: cover the alternate signature and degrade to no-op\nDynMethods.UnboundMethod m = new DynMethods.Builder(\"handle\")\n    .impl(signalClass, handlerClass)\n    .orNoop()\n    .build();","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"static boolean hasMethod(Class<?> target, String name, Class<?>... args) {\n  try {\n    target.getDeclaredMethod(name, args);\n    return true;\n  } catch (NoSuchMethodException e) {\n    return false;\n  }\n}","tryCatchPattern":"DynMethods.UnboundMethod m;\ntry {\n  m = new DynMethods.Builder(\"handle\").impl(cls, handlerClass).buildChecked();\n} catch (NoSuchMethodException e) {\n  LOG.warn(\"optional binding 'handle' unavailable on this runtime; degrading\", e);\n  m = null;\n}","preventionTips":["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"],"tags":["hadoop","java","reflection","jdk-compatibility","classpath"],"backgroundTag":"reflection-method-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}