{"record":{"id":"8d8cad9779d2e4ae","repo":"apache/hadoop","slug":"file-does-not-exist-8d8cad","errorCode":null,"errorMessage":"File does not exist: {}","messagePattern":"File does not exist: (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/fs/Hdfs.java","lineNumber":153,"sourceCode":"    return dfs.getFileChecksumWithCombineMode(getUriPath(f), Long.MAX_VALUE);\n  }\n\n  /**\n   * {@inheritDoc}\n   *\n   * If the given path is a symlink, the path will be resolved to a target path\n   * and it will get the resolved path's FileStatus object. It will not be\n   * represented as a symlink and isDirectory API returns true if the resolved\n   * path is a directory, false otherwise.\n   */\n  @Override\n  public FileStatus getFileStatus(Path f) \n      throws IOException, UnresolvedLinkException {\n    HdfsFileStatus fi = dfs.getFileInfo(getUriPath(f));\n    if (fi != null) {\n      return fi.makeQualified(getUri(), f);\n    } else {\n      throw new FileNotFoundException(\"File does not exist: \" + f.toString());\n    }\n  }\n\n  /**\n   * Synchronize client metadata state with Active NameNode.\n   * <p>\n   * In HA the client synchronizes its state with the Active NameNode\n   * in order to guarantee subsequent read consistency from Observer Nodes.\n   * @throws IOException\n   */\n  @Override\n  public void msync() throws IOException {\n    dfs.msync();\n  }\n\n  @Override\n  public FileStatus getFileLinkStatus(Path f) \n      throws IOException, UnresolvedLinkException {","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/fs/Hdfs.java#L135-L171","documentation":"Hdfs.getFileStatus asks DFSClient.getFileInfo for the path; a null response means the NameNode has no entry for it, which becomes FileNotFoundException(\"File does not exist: \" + path). This is the FileContext-level twin of the FileSystem version — thrown for a genuinely missing path, not for permission problems (those surface as AccessControlException) and not for broken symlinks (UnresolvedLinkException).","triggerScenarios":"fc.getFileStatus(path) on a path that was deleted, never existed, contains a typo, or is being addressed through the wrong authority (a different cluster or nameservice) where it legitimately does not exist.","commonSituations":"TOCTOU races where a file is deleted between listing and stat; relative paths resolved against an unexpected working directory/defaultFS; scripts pointed at the standby or DR cluster after failover.","solutions":["Verify with `hdfs dfs -ls` against the same fs.defaultFS the code uses","Catch FileNotFoundException and treat it as an expected outcome (skip, recreate, or report)","For racy paths, re-check with fc.util().exists() or listStatus and tolerate absence"],"exampleFix":"// before\nFileStatus st = fc.getFileStatus(p);\n\n// after\nFileStatus st;\ntry {\n  st = fc.getFileStatus(p);\n} catch (FileNotFoundException e) {\n  return; // treat as absent\n}","handlingStrategy":"try-catch","validationCode":"if (!fc.util().exists(p)) {\n  // absent: skip, create parent, or report — do not call getFileStatus\n}","typeGuard":null,"tryCatchPattern":"try {\n  FileStatus st = fc.getFileStatus(p);\n} catch (FileNotFoundException e) {\n  // expected when racing with deletions; handle absence explicitly\n}","preventionTips":["Use fc.util().exists() when absence is normal and races are unlikely","Resolve paths against a known fs.defaultFS to avoid stat-ing the wrong cluster","Treat FileNotFoundException as control flow, not an error to log at FATAL"],"tags":["hdfs","file-not-found","io","hadoop"],"backgroundTag":"file-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}