{"record":{"id":"024cb719f5059f4b","repo":"apache/hadoop","slug":"unable-to-parse-arguments-args","errorCode":null,"errorMessage":"Unable to parse arguments. {args}","messagePattern":"Unable to parse arguments\\. (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/OptionsParser.java","lineNumber":93,"sourceCode":"\n  /**\n   * The parse method parses the command-line options, and creates\n   * a corresponding Options object.\n   * @param args Command-line arguments (excluding the options consumed\n   *              by the GenericOptionsParser).\n   * @return The Options object, corresponding to the specified command-line.\n   * @throws IllegalArgumentException Thrown if the parse fails.\n   */\n  public static DistCpOptions parse(String[] args)\n      throws IllegalArgumentException {\n\n    CommandLineParser parser = new CustomParser();\n\n    CommandLine command;\n    try {\n      command = parser.parse(cliOptions, args, true);\n    } catch (ParseException e) {\n      throw new IllegalArgumentException(\"Unable to parse arguments. \" +\n        Arrays.toString(args), e);\n    }\n\n    DistCpOptions.Builder builder = parseSourceAndTargetPaths(command);\n    builder\n        .withAtomicCommit(\n            command.hasOption(DistCpOptionSwitch.ATOMIC_COMMIT.getSwitch()))\n        .withSyncFolder(\n            command.hasOption(DistCpOptionSwitch.SYNC_FOLDERS.getSwitch()))\n        .withDeleteMissing(\n            command.hasOption(DistCpOptionSwitch.DELETE_MISSING.getSwitch()))\n        .withIgnoreFailures(\n            command.hasOption(DistCpOptionSwitch.IGNORE_FAILURES.getSwitch()))\n        .withOverwrite(\n            command.hasOption(DistCpOptionSwitch.OVERWRITE.getSwitch()))\n        .withAppend(\n            command.hasOption(DistCpOptionSwitch.APPEND.getSwitch()))\n        .withSkipCRC(","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/OptionsParser.java#L75-L111","documentation":"The Apache Commons-CLI parse of the distcp command line failed and is rethrown as IllegalArgumentException with the ParseException chained as the cause. Common causes: an unrecognized option, an option that requires a value but got none, or an argument that starts with '-' being consumed as a new option. The inner CustomParser only rewrites a bare -p to the default preserve set, so anything else unexpected is a hard parse failure.","triggerScenarios":"Misspelled or unknown switch, e.g. -updat or a long form like --bandwidth that is not registered; -m or -p with a missing value; an option value that itself begins with '-' (e.g. -blocksPerChunk -5) so commons-cli treats it as the next option; shell globbing splitting one argument into stray tokens.","commonSituations":"typos in switches; copying commands from a different Hadoop version whose switches differ; unquoted arguments containing spaces or glob characters; negative or dash-prefixed values; scripts concatenating unset variables producing '-'.","solutions":["Print supported usage with 'hadoop distcp -h' and fix the offending switch (typo or unsupported long form is the most common).","Read the chained cause in the stack trace - commons-cli names the exact problem ('Unrecognized option: -x', 'Missing argument for option: m').","Quote every argument containing spaces or glob characters so the shell delivers it intact.","If a value must start with '-', restructure the value or drop the dash - commons-cli cannot be told otherwise here."],"exampleFix":"# before: typo 'updat' -> Unrecognized option, wrapped as Unable to parse arguments\nhadoop distcp -updat -append hdfs://nn/src hdfs://nn/tgt\n\n# after\nhadoop distcp -update -append hdfs://nn/src hdfs://nn/tgt","handlingStrategy":"validation","validationCode":"// Programmatic callers: dry-run the parse before submitting anything\ntry {\n  DistCpOptions opts = OptionsParser.parse(args);\n} catch (IllegalArgumentException e) {\n  // e.getCause() is the ParseException naming the exact bad token\n  System.err.println(\"Bad distcp arguments: \" + e.getCause().getMessage());\n  throw e;\n}","typeGuard":null,"tryCatchPattern":"try {\n  ToolRunner.run(new DistCp(conf, opts), args);\n} catch (IllegalArgumentException e) {\n  Throwable cause = e.getCause();\n  if (cause instanceof ParseException) {\n    // argument error: report token + usage and exit; retrying cannot help\n    System.err.println(\"Parse failed: \" + cause.getMessage());\n  } else {\n    throw e;\n  }\n}","preventionTips":["Keep distcp invocations in a reviewed script; run `hadoop distcp -h` when adding flags.","Quote every argument containing spaces or glob characters.","Avoid option values that begin with '-'.","Copy commands only from the docs of the Hadoop version you run."],"tags":["distcp","cli","commons-cli","argument-parsing","invalid-arguments"],"backgroundTag":"cli-argument-parse-error","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}