{"record":{"id":"8e74982230a65015","repo":"apache/hadoop","slug":"file-f-does-not-exist","errorCode":null,"errorMessage":"File \" + f + \" does not exist","messagePattern":"File \" \\+ f \\+ \" does not exist","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java","lineNumber":817,"sourceCode":"        (FileUtil.listFiles(f).length != 0)) {\n      throw new IOException(\"Directory \" + f.toString() + \" is not empty\");\n    }\n    return FileUtil.fullyDelete(f);\n  }\n \n  /**\n   * {@inheritDoc}\n   *\n   * (<b>Note</b>: Returned list is not sorted in any given order,\n   * due to reliance on Java's {@link File#list()} API.)\n   */\n  @Override\n  public FileStatus[] listStatus(Path f) throws IOException {\n    File localf = pathToFile(f);\n    FileStatus[] results;\n\n    if (!localf.exists()) {\n      throw new FileNotFoundException(\"File \" + f + \" does not exist\");\n    }\n\n    if (localf.isDirectory()) {\n      String[] names = FileUtil.list(localf);\n      results = new FileStatus[names.length];\n      int j = 0;\n      for (int i = 0; i < names.length; i++) {\n        try {\n          // Assemble the path using the Path 3 arg constructor to make sure\n          // paths with colon are properly resolved on Linux\n          results[j] = getFileStatus(new Path(f, new Path(null, null,\n                                                          names[i])));\n          j++;\n        } catch (FileNotFoundException e) {\n          // ignore the files not found since the dir list may have have\n          // changed since the names[] list was generated.\n        }\n      }","sourceCodeStart":799,"sourceCodeEnd":835,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java#L799-L835","documentation":"RawLocalFileSystem.listStatus(Path) stats the local file first and throws FileNotFoundException('File ... does not exist') when the path is absent. This mirrors the contract of the abstract FileSystem: listing a missing path is an error, not an empty array. The underlying cause is a plain missing local file or symlink chain.","triggerScenarios":"Calling fs.listStatus(p) where p does not exist on local disk: input directory moved or renamed, typo in configuration, a job submitted before the input stage produced the directory, or a dangling symlink (stat on the link target fails).","commonSituations":"Pipeline stages run out of order so the consumer lists before the producer writes, input paths from core-site.xml pointing at renamed mounts, containers where the volume was not mounted, or code ported from an environment where the directory existed.","solutions":["Verify on disk: ls -ld the exact path; fix typos or update the configuration to the real location.","Guard in code: if (!fs.exists(p)) handle-missing (create, skip, or fail with your own message).","Order pipeline stages so inputs exist before listing; poll for a _SUCCESS marker before consuming.","For symlinks, confirm the target exists with Files.readSymbolicLink / readlink."],"exampleFix":"// before\nfor (FileStatus st : fs.listStatus(inputDir)) { ... } // throws if missing\n\n// after\nif (!fs.exists(inputDir)) {\n  throw new FileNotFoundException(\"Input not ready: \" + inputDir);\n}\nfor (FileStatus st : fs.listStatus(inputDir)) { ... }","handlingStrategy":"validation","validationCode":"if (!fs.exists(dir)) {\n  throw new FileNotFoundException(\n      \"Input directory missing (producer not run?): \" + dir);\n}\nFileStatus[] entries = fs.listStatus(dir);","typeGuard":null,"tryCatchPattern":"try {\n  return fs.listStatus(dir);\n} catch (FileNotFoundException e) {\n  // distinguish expected-missing from misconfiguration before swallowing\n  LOG.warn(\"Input {} missing; treating as empty\", dir);\n  return new FileStatus[0];\n}","preventionTips":["Check exists() before listStatus; missing input is an error, not an empty list.","Use absolute, qualified Paths to avoid working-directory mismatches.","Gate pipeline stages on completion markers (_SUCCESS) rather than hoping inputs exist."],"tags":["hadoop","local-filesystem","liststatus","file-not-found","filenotfoundexception"],"backgroundTag":"file-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}