{"record":{"id":"c1aec45e18abbf6d","repo":"apache/hadoop","slug":"target-path-not-specified","errorCode":null,"errorMessage":"Target path not specified","messagePattern":"Target path not specified","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/OptionsParser.java","lineNumber":259,"sourceCode":"\n    return builder.build();\n  }\n\n  /**\n   * parseSourceAndTargetPaths is a helper method for parsing the source\n   * and target paths.\n   *\n   * @param command command line arguments\n   * @return        DistCpOptions\n   */\n  private static DistCpOptions.Builder parseSourceAndTargetPaths(\n      CommandLine command) {\n    Path targetPath;\n    List<Path> sourcePaths = new ArrayList<Path>();\n\n    String[] leftOverArgs = command.getArgs();\n    if (leftOverArgs == null || leftOverArgs.length < 1) {\n      throw new IllegalArgumentException(\"Target path not specified\");\n    }\n\n    //Last Argument is the target path\n    targetPath = new Path(leftOverArgs[leftOverArgs.length - 1].trim());\n\n    //Copy any source paths in the arguments to the list\n    for (int index = 0; index < leftOverArgs.length - 1; index++) {\n      sourcePaths.add(new Path(leftOverArgs[index].trim()));\n    }\n\n    /* If command has source file listing, use it else, fall back on source\n       paths in args.  If both are present, throw exception and bail */\n    if (command.hasOption(\n        DistCpOptionSwitch.SOURCE_FILE_LISTING.getSwitch())) {\n      if (!sourcePaths.isEmpty()) {\n        throw new IllegalArgumentException(\"Both source file listing and \" +\n            \"source paths present\");\n      }","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/OptionsParser.java#L241-L277","documentation":"DistCp takes sources and target from the positional (non-option) arguments; the last positional argument is the target. parseSourceAndTargetPaths found command.getArgs() null or empty, meaning every token was consumed as an option or option value and no target path survived. Note that -f consumes its file path as the option's value - so '-f <file>' with nothing after it leaves zero positional args.","triggerScenarios":"hadoop distcp -update (switches only, no paths); hadoop distcp -f /tmp/list.txt (forgot the trailing target); a wrapper script interpolating an unset $TARGET variable so the token never appears.","commonSituations":"scripts dropping the target when a variable is empty; forgetting that -f takes its value inline and the target must still be appended; interactive typos truncating the command.","solutions":["Append the destination as the last positional argument: hadoop distcp <options> <src...> <target>.","With -f, the target still must follow the file: hadoop distcp -f <listfile> <target>.","Echo the fully expanded command in wrapper scripts to catch unset variables before submission."],"exampleFix":"# before: -f consumes /tmp/list.txt as its value; no positional target remains\nhadoop distcp -f /tmp/list.txt\n\n# after\nhadoop distcp -f /tmp/list.txt hdfs://nn/tgt","handlingStrategy":"validation","validationCode":"// Wrapper validation: at least one positional (non-option) argument must remain\n// after option parsing; the last one is the target.\nint positional = 0;\nfor (String a : args) {\n  if (!a.startsWith(\"-\")) positional++; // approximation; use commons-cli for exactness\n}\nif (positional < 1) {\n  throw new IllegalArgumentException(\"Target path missing; usage: distcp <opts> <src...> <target>\");\n}\n// shell: [ -n \"$TARGET\" ] || { echo \"TARGET unset\"; exit 2; }","typeGuard":null,"tryCatchPattern":"try {\n  OptionsParser.parse(args);\n} catch (IllegalArgumentException e) {\n  if (\"Target path not specified\".equals(e.getMessage())) {\n    throw new IllegalArgumentException(\"Append the destination as the last argument\", e);\n  }\n  throw e;\n}","preventionTips":["Remember -f consumes its value inline - the target must still be the last positional argument.","Set -u (nounset) in wrapper scripts so unset TARGET/SRC variables abort early.","Echo the fully expanded command before submission."],"tags":["distcp","cli","missing-argument","target-path"],"backgroundTag":"missing-required-cli-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}