{"record":{"id":"542751e79e8bfb0a","repo":"apache/hadoop","slug":"bad-argument","errorCode":null,"errorMessage":"Bad argument: {}","messagePattern":"Bad argument: (.+?)","errorType":"exception","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ZKFailoverController.java","lineNumber":277,"sourceCode":"    } catch (Exception e) {\n      LOG.error(\"The failover controller encounters runtime error: \", e);\n      throw e;\n    } finally {\n      rpcServer.stopAndJoin();\n      \n      elector.quitElection(true);\n\n      if (healthMonitor != null) {\n        healthMonitor.shutdown();\n        healthMonitor.join();\n      }\n    }\n    return 0;\n  }\n\n  private void badArg(String arg) {\n    printUsage();\n    throw new HadoopIllegalArgumentException(\n        \"Bad argument: \" + arg);\n  }\n\n  private void printUsage() {\n    System.err.println(USAGE + \"\\n\");\n  }\n\n  private int formatZK(boolean force, boolean interactive)\n      throws IOException, InterruptedException, KeeperException {\n    if (elector.parentZNodeExists()) {\n      if (!force && (!interactive || !confirmFormat())) {\n        return ERR_CODE_FORMAT_DENIED;\n      }\n      \n      try {\n        elector.clearParentZNode();\n      } catch (IOException e) {\n        LOG.error(\"Unable to clear zk parent znode\", e);","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ZKFailoverController.java#L259-L295","documentation":"ZKFailoverController.badArg(String) prints USAGE to stderr and throws HadoopIllegalArgumentException('Bad argument: <arg>') when the ZKFC process is started with an unrecognized command-line argument. Usage is: 'hdfs zkfc [ -formatZK [-force] [-nonInteractive] ]'.","triggerScenarios":"Launching the ZKFailoverController (hdfs zkfc / DFZKFailoverController subclass) with an unknown or misspelled flag, e.g. '-formatZ' instead of '-formatZK', or passing extra positional args after valid ones.","commonSituations":"Typos in startup scripts; scripts written for a different tool passing NameNode-style flags; custom ZKFailoverController subclasses (e.g. HDFS-ized ones) that accept extra args but the base class rejects them.","solutions":["Run with no arguments or '-h' to print USAGE; only -formatZK, -force, -nonInteractive (and -h) are accepted here.","Fix the typo in the start script or systemd/init definition.","For custom arguments, parse them in the subclass's parseArgs before delegating to super, instead of passing them through."],"exampleFix":"# before\nhdfs zkfc -formatZ --force\n\n# after\nhdfs zkfc -formatZK -force -nonInteractive","handlingStrategy":"validation","validationCode":"Set<String> allowed = Set.of(\"-h\", \"-formatZK\", \"-force\", \"-nonInteractive\");\nfor (String a : args) {\n  if (!allowed.contains(a)) {\n    throw new IllegalArgumentException(\"Unknown ZKFC argument: \" + a);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  System.exit(ToolRunner.run(conf, new DFZKFailoverController(), args));\n} catch (HadoopIllegalArgumentException e) {\n  // USAGE was already printed; fix the flags in the launcher script\n}","preventionTips":["Copy the exact flags from 'hdfs zkfc' USAGE: -formatZK, -force, -nonInteractive.","Validate ZKFC launcher args in the same lint pass as JVM options in startup scripts.","Run 'hdfs zkfc -h' once when scripting changes that touch daemon flags."],"tags":["hadoop","high-availability","zkfc","cli","usage"],"backgroundTag":"invalid-command-line-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}