{"record":{"id":"1c117989b2452584","repo":"apache/hadoop","slug":"target-path-s-does-not-exist-or-is-not-file","errorCode":null,"errorMessage":"Target path %s does not exist or is not file.","messagePattern":"Target path (.+?) does not exist or is not file\\.","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Concat.java","lineNumber":62,"sourceCode":"  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    }\n    FileSystem fs = target.fs;\n    if (testFs != null) {\n      fs = testFs;\n    }\n    try {\n      fs.concat(target.path, srcArray);","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Concat.java#L44-L80","documentation":"Thrown by Concat.processArguments() when the first argument (the target) does not exist or is not a regular file: !target.exists || !target.stat.isFile() raises FileNotFoundException('Target path <p> does not exist or is not file.'). concat appends source blocks TO the existing target, so the target must already be a file; each source is validated the same way in the following loop ('<src> does not exist or is not file.').","triggerScenarios":"'hdfs dfs concat /data/missing /a /b'; target is a directory; target created by a previous step that failed silently; sources include a directory or a path deleted between listing and concat.","commonSituations":"Compaction flows where the 'target' was meant to be created by an earlier job (e.g. via -touchz or getmerge) that did not run; passing the directory path instead of the base part file.","solutions":["Create the target file first ('hdfs dfs -touchz /data/target' or copy the first part to the target name), then concat the REMAINING parts into it","Verify each argument with 'hdfs dfs -ls' (or fs.getFileStatus().isFile() in Java) before invoking concat","Ensure sources and target are in the same directory and all are regular files"],"exampleFix":"# before\nhdfs dfs concat /data/target /data/part-0 /data/part-1   # /data/target absent\n# after\nhdfs dfs -cp /data/part-0 /data/target && hdfs dfs concat /data/target /data/part-1","handlingStrategy":"validation","validationCode":"// every concat argument must be an existing regular file\nstatic void validateConcatArgs(FileSystem fs, Path target, List<Path> srcs) throws IOException {\n  if (!fs.exists(target) || !fs.getFileStatus(target).isFile())\n    throw new FileNotFoundException(\"target must be an existing file: \" + target);\n  for (Path s : srcs) {\n    if (!fs.exists(s) || !fs.getFileStatus(s).isFile())\n      throw new FileNotFoundException(\"source must be an existing file: \" + s);\n  }\n}","typeGuard":"static boolean isExistingFile(FileSystem fs, Path p) throws IOException {\n  return fs.exists(p) && !fs.getFileStatus(p).isDirectory();\n}","tryCatchPattern":"try {\n  fs.concat(target, srcArray); // hdfs dfs concat path\n} catch (FileNotFoundException e) {\n  // bootstrap the target from the first part, then concat the remainder\n  fs.rename(srcArray[0], target);\n  fs.concat(target, Arrays.copyOfRange(srcArray, 1, srcArray.length));\n}","preventionTips":["Create the target first (touchz or copy part-0 to the target name) as a fixed step of compaction jobs","Validate target AND all sources as regular files before invoking concat","Keep target and sources in the same directory with identical block size and replication"],"tags":["hadoop","hdfs","concat","file-validation","shell","java"],"backgroundTag":"target-not-a-file","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}