{"record":{"id":"473328c1ebf52732","repo":"apache/hadoop","slug":"the-number-of-source-paths-is-less-than-2-target","errorCode":null,"errorMessage":"The number of source paths is less than 2. <target path> <src path> <src path> ...","messagePattern":"The number of source paths is less than 2\\. <target path> <src path> <src path> \\.\\.\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Concat.java","lineNumber":56,"sourceCode":"  public static void registerCommands(CommandFactory factory) {\n    factory.addClass(Concat.class, \"-concat\");\n  }\n\n  public static final String NAME = \"concat\";\n  public static final String USAGE = \"<target path> <src path> <src path> ...\";\n  public static final String DESCRIPTION = \"Concatenate existing source files\"\n      + \" into the target file. Target file and source files should be in the\"\n      + \" same directory.\";\n  private static FileSystem testFs; // test only.\n\n  @Override\n  protected void processArguments(LinkedList<PathData> args)\n      throws IOException {\n    if (args.size() < 1) {\n      throw new IOException(\"Target path not specified. \" + USAGE);\n    }\n    if (args.size() < 3) {\n      throw new IOException(\n          \"The number of source paths is less than 2. \" + USAGE);\n    }\n    PathData target = args.removeFirst();\n    LinkedList<PathData> srcList = args;\n    if (!target.exists || !target.stat.isFile()) {\n      throw new FileNotFoundException(String\n          .format(\"Target path %s does not exist or is\" + \" not file.\",\n              target.path));\n    }\n    Path[] srcArray = new Path[srcList.size()];\n    for (int i = 0; i < args.size(); i++) {\n      PathData src = srcList.get(i);\n      if (!src.exists || !src.stat.isFile()) {\n        throw new FileNotFoundException(\n            String.format(\"%s does not exist or is not file.\", src.path));\n      }\n      srcArray[i] = src.path;\n    }","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Concat.java#L38-L74","documentation":"Thrown by Concat.processArguments() when fewer than 3 total arguments remain (target plus fewer than 2 sources). FileSystem.concat() with fewer than two parts is meaningless or unsupported, so the shell pre-empts it with IOException('The number of source paths is less than 2. <target path> <src path> <src path> ...').","triggerScenarios":"'hdfs dfs concat /data/target /data/part-0' (only one source); glob for sources expanding to a single file; source list built by a loop that appended fewer entries than expected.","commonSituations":"Compaction jobs whose input filter matched only one file for the period; hand-testing concat with one part before the real run.","solutions":["Pass at least two existing source files along with the target","Check the number of matches first (e.g. count 'hdfs dfs -ls /data/part-*' output) and skip concat when < 2","If only one part exists, copy/append it with a different command instead of concat"],"exampleFix":"# before\nhdfs dfs concat /data/target /data/part-0\n# after\nhdfs dfs concat /data/target /data/part-0 /data/part-1","handlingStrategy":"validation","validationCode":"// require target + >=2 sources\nif (positionalArgs.size() < 3) {\n  throw new IllegalArgumentException(\n    \"need at least 3 paths (target + 2 sources), got \" + positionalArgs.size());\n}","typeGuard":null,"tryCatchPattern":"try {\n  shellRun(concatArgs);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"less than 2\")) {\n    // not enough parts to justify a concat; fall back to a plain copy for the single part\n    shellRun(\"-cp\", singleSource, target);\n  } else throw e;\n}","preventionTips":["Count the matched parts before calling concat; skip when fewer than 2","Beware globs that expand to exactly one file in quiet periods","Prefer HDFS concatenation via FileSystem.concat in Java where the compiler enforces the array"],"tags":["hadoop","hdfs","concat","argument-validation","shell","java"],"backgroundTag":"missing-required-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}