{"record":{"id":"45b79d67e525e9e7","repo":"apache/hadoop","slug":"class-does-not-implement-fencemethod","errorCode":null,"errorMessage":"Class {} does not implement FenceMethod","messagePattern":"Class (.+?) does not implement FenceMethod","errorType":"exception","errorClass":"BadFencingConfigurationException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/NodeFencer.java","lineNumber":187,"sourceCode":"      throws BadFencingConfigurationException {\n\n    Class<?> clazz;\n    try {\n      // See if it's a short name for one of the built-in methods\n      clazz = STANDARD_METHODS.get(clazzName);\n      if (clazz == null) {\n        // Try to instantiate the user's custom method\n        clazz = Class.forName(clazzName);\n      }\n    } catch (Exception e) {\n      throw new BadFencingConfigurationException(\n          \"Could not find configured fencing method \" + clazzName,\n          e);\n    }\n    \n    // Check that it implements the right interface\n    if (!FenceMethod.class.isAssignableFrom(clazz)) {\n      throw new BadFencingConfigurationException(\"Class \" + clazzName +\n          \" does not implement FenceMethod\");\n    }\n    \n    FenceMethod method = (FenceMethod)ReflectionUtils.newInstance(\n        clazz, conf);\n    method.checkArgs(arg);\n    return new FenceMethodWithArg(method, arg);\n  }\n  \n  private static class FenceMethodWithArg {\n    private final FenceMethod method;\n    private final String arg;\n    \n    private FenceMethodWithArg(FenceMethod method, String arg) {\n      this.method = method;\n      this.arg = arg;\n    }\n    ","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/NodeFencer.java#L169-L205","documentation":"NodeFencer throws BadFencingConfigurationException('Class <name> does not implement FenceMethod') when the configured fencing class loads but does not implement org.apache.hadoop.ha.FenceMethod, so it cannot be instantiated as a fencer.","triggerScenarios":"dfs.ha.fencing.methods names a class that exists on the classpath but lacks the FenceMethod interface — e.g. a utility class, or a custom fencer compiled against a different signature/interface version.","commonSituations":"Config pointing at the wrong class in a jar (same name, different package role); custom fencer not declared 'implements FenceMethod'; binary incompatibility after a Hadoop upgrade.","solutions":["Make the custom class implement org.apache.hadoop.ha.FenceMethod (checkArgs(String) and tryFence(HAServiceTarget, String)).","Or point the configuration at a class that already implements it: org.apache.hadoop.ha.SshFenceByTcpPort or org.apache.hadoop.ha.ShellCommandFencer.","Recompile against the running Hadoop version, redeploy the jar to all nodes, and restart."],"exampleFix":"// before: plain class, not a FenceMethod\npublic class MyFencer {\n  public boolean fence(HAServiceTarget t, String args) { return true; }\n}\n\n// after: implements org.apache.hadoop.ha.FenceMethod\npublic class MyFencer implements FenceMethod {\n  @Override public void checkArgs(String args) throws BadFencingConfigurationException { }\n  @Override public boolean tryFence(HAServiceTarget target, String args) { /* ... */ return true; }\n}","handlingStrategy":"validation","validationCode":"Class<?> c = Class.forName(configuredFencer);\nif (!org.apache.hadoop.ha.FenceMethod.class.isAssignableFrom(c)) {\n  throw new IllegalStateException(configuredFencer + \" does not implement FenceMethod\");\n}","typeGuard":"boolean isFenceMethod(Class<?> c) {\n  return org.apache.hadoop.ha.FenceMethod.class.isAssignableFrom(c);\n}","tryCatchPattern":"try {\n  new NodeFencer(conf, fencingConfig);\n} catch (BadFencingConfigurationException e) {\n  if (e.getMessage().contains(\"does not implement FenceMethod\")) {\n    // fix the class to implement checkArgs/tryFence, recompile, redeploy\n  }\n}","preventionTips":["Compile custom fencers against the exact Hadoop version in the cluster and keep the interface method signatures (checkArgs(String), tryFence(HAServiceTarget,String)).","Add a unit test that does 'new NodeFencer(conf, configuredValue)' against the shipped config.","Prefer built-in fencers unless a custom one is truly required."],"tags":["hadoop","configuration","fencing","interface","classpath"],"backgroundTag":"interface-implementation-missing","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}