{"record":{"id":"404e7ff966048e96","repo":"apache/hadoop","slug":"file-does-not-exist-f","errorCode":null,"errorMessage":"File does not exist: ${f}","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/hdfs/web/WebHdfsFileSystem.java","lineNumber":1116,"sourceCode":"\n  private FsPermission applyUMask(FsPermission permission) {\n    if (permission == null) {\n      permission = FsPermission.getDefault();\n    }\n    return FsCreateModes.applyUMask(permission,\n        FsPermission.getUMask(getConf()));\n  }\n\n  private HdfsFileStatus getHdfsFileStatus(Path f) throws IOException {\n    final HttpOpParam.Op op = GetOpParam.Op.GETFILESTATUS;\n    HdfsFileStatus status = new FsPathResponseRunner<HdfsFileStatus>(op, f) {\n      @Override\n      HdfsFileStatus decodeResponse(Map<?,?> json) {\n        return JsonUtilClient.toFileStatus(json, true);\n      }\n    }.run();\n    if (status == null) {\n      throw new FileNotFoundException(\"File does not exist: \" + f);\n    }\n    return status;\n  }\n\n  @Override\n  public FileStatus getFileStatus(Path f) throws IOException {\n    statistics.incrementReadOps(1);\n    storageStatistics.incrementOpCounter(OpType.GET_FILE_STATUS);\n    return getHdfsFileStatus(f).makeQualified(getUri(), f);\n  }\n\n  @Override\n  public AclStatus getAclStatus(Path f) throws IOException {\n    final HttpOpParam.Op op = GetOpParam.Op.GETACLSTATUS;\n    AclStatus status = new FsPathResponseRunner<AclStatus>(op, f) {\n      @Override\n      AclStatus decodeResponse(Map<?,?> json) {\n        return JsonUtilClient.toAclStatus(json);","sourceCodeStart":1098,"sourceCodeEnd":1134,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java#L1098-L1134","documentation":"getHdfsFileStatus issues WebHDFS GETFILESTATUS and decodes the response into an HdfsFileStatus. If decoding yields null, most often because the response body is empty or contains no status object, the client throws FileNotFoundException with the requested path. This also covers the ordinary case where the path is not present in the namespace.","triggerScenarios":"Calling getFileStatus(path) on a webhdfs:// path that does not exist, or when the NameNode/gateway returns an empty body for GETFILESTATUS. Relative paths are resolved against the current working directory, so the effective path may differ from the string supplied by the application.","commonSituations":"Reading before a writer creates or commits the file; wrong working directory; typo or missing leading slash; a path created under another user's namespace; races with delete/rename.","solutions":["Log the qualified path, fs.makeQualified(path), and compare it with the path shown in the exception.","Create or wait for the parent/file to be committed before requesting status.","Use explicit absolute paths in jobs to avoid dependence on the client working directory.","If deletion or rename can race with the caller, treat FileNotFoundException as an expected outcome rather than retrying the same operation."],"exampleFix":"// before\nFileStatus status = fs.getFileStatus(new Path(\"input/data.csv\"));\n\n// after\nPath f = fs.makeQualified(new Path(\"/user/alice/input/data.csv\"));\ntry {\n  return fs.getFileStatus(f);\n} catch (FileNotFoundException e) {\n  LOG.info(\"Input not committed yet: {}\", f);\n  return null;\n}","handlingStrategy":"try-catch","validationCode":"Path qualified = fs.makeQualified(path);\nif (!fs.exists(qualified)) {\n  throw new FileNotFoundException(\"Expected input is missing: \" + qualified);\n}","typeGuard":null,"tryCatchPattern":"try {\n  return fs.getFileStatus(f);\n} catch (FileNotFoundException e) {\n  if (optionalInputs.contains(f)) {\n    return null;\n  }\n  throw new MissingInputException(\"Required HDFS input does not exist: \" + f, e);\n}","preventionTips":["Qualify paths once at job setup so working-directory changes cannot alter their meaning.","Wait for commit markers before consuming outputs from another job.","Distinguish optional missing inputs from required ones when handling FileNotFoundException."],"tags":["java","hadoop","webhdfs","file-not-found","path"],"backgroundTag":"file-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}