{"record":{"id":"3afe16c17ea0e8ab","repo":"apache/hadoop","slug":"invalid-or-extra-arguments","errorCode":null,"errorMessage":"Invalid or extra Arguments: {}","messagePattern":"Invalid or extra Arguments: (.+?)","errorType":"validation","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DiskBalancerCLI.java","lineNumber":197,"sourceCode":"      res = 1;\n    }\n    System.exit(res);\n  }\n\n  /**\n   * Execute the command with the given arguments.\n   *\n   * @param args command specific arguments.\n   * @return exit code.\n   * @throws Exception\n   */\n  @Override\n  public int run(String[] args) throws Exception {\n    Options opts = getOpts();\n    CommandLine cmd = parseArgs(args, opts);\n    String[] cmdArgs = cmd.getArgs();\n    if (cmdArgs.length > 2) {\n      throw new HadoopIllegalArgumentException(\n          \"Invalid or extra Arguments: \" + Arrays\n              .toString(Arrays.copyOfRange(cmdArgs, 2, cmdArgs.length)));\n    }\n    return dispatch(cmd);\n  }\n\n  /**\n   * returns the Command Line Options.\n   *\n   * @return Options\n   */\n  private Options getOpts() {\n    Options opts = new Options();\n    addPlanCommands(opts);\n    addHelpCommands(opts);\n    addExecuteCommands(opts);\n    addQueryCommands(opts);\n    addCancelCommands(opts);","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DiskBalancerCLI.java#L179-L215","documentation":"DiskBalancerCLI ('hdfs diskbalancer') parses options with commons-cli and then inspects the leftover positional arguments. Only two positional tokens are legal: the subcommand (plan/execute/query/cancel/report/help) plus at most one operand (e.g. the hostname for -plan or the plan file path for -execute). Anything beyond index 1 is rejected with this HadoopIllegalArgumentException listing the extra tokens.","triggerScenarios":"Invoking e.g. 'hdfs diskbalancer -execute plan.json nodeplan.json extra' (three positionals), or passing a value that the parser does not recognize as an option so it lands in getArgs(), or quoting mistakes that split one operand into several tokens.","commonSituations":"Copy-pasted commands with a stale extra argument; users adding a node list where only one host is accepted; scripts appending unquoted paths containing spaces.","solutions":["Run 'hdfs diskbalancer -help' and match the subcommand syntax exactly (plan takes one host, execute takes one plan file path).","Remove the extra positional tokens named in the error message.","Quote operand values containing spaces and double-check that option values use '-' prefixed flags (e.g. -bandwidth 10) so they are not treated as positionals."],"exampleFix":"# before\nhdfs diskbalancer -execute /system/diskbalancer/plan.json /system/diskbalancer/node.json\n# Invalid or extra Arguments: [node.json]\n\n# after\nhdfs diskbalancer -execute /system/diskbalancer/plan.json","handlingStrategy":"validation","validationCode":"// commons-cli style pre-check before DiskBalancerCLI.run\nCommandLine cmd = parser.parse(getOpts(), args);\nString[] positional = cmd.getArgs();\nif (positional.length > 2) {\n  throw new IllegalArgumentException(\"diskbalancer accepts at most 2 positional \"\n      + \"arguments (command, operand); got \" + Arrays.toString(positional));\n}\ncli.run(args);","typeGuard":null,"tryCatchPattern":"try {\n  return diskBalancerCLI.run(args);\n} catch (HadoopIllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Invalid or extra Arguments\")) {\n    System.err.println(\"Usage error; see 'hdfs diskbalancer -help'. Extra args: \"\n        + e.getMessage());\n    return 1; // usage failure, not a cluster failure\n  }\n  throw e;\n}","preventionTips":["Validate argument counts in wrapper scripts before invoking the CLI.","Quote operands (plan file paths) so spaces never split into extra tokens.","Build commands from the '-help' output of the exact Hadoop version in use."],"tags":["hadoop","hdfs","diskbalancer","cli","arguments"],"backgroundTag":"invalid-cli-arguments","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}