{"record":{"id":"a00f25ce1655d1bc","repo":"apache/hadoop","slug":"file-original-does-not-exist","errorCode":null,"errorMessage":"File \" + original + \" does not exist","messagePattern":"File \" \\+ original \\+ \" does not exist","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Stat.java","lineNumber":121,"sourceCode":"          path.toString() };\n    } else {\n      throw new UnsupportedOperationException(\n          \"stat is not supported on this platform\");\n    }\n  }\n\n  @Override\n  protected void parseExecResult(BufferedReader lines) throws IOException {\n    // Reset stat\n    stat = null;\n\n    String line = lines.readLine();\n    if (line == null) {\n      throw new IOException(\"Unable to stat path: \" + original);\n    }\n    if (line.endsWith(\"No such file or directory\") ||\n        line.endsWith(\"Not a directory\")) {\n      throw new FileNotFoundException(\"File \" + original + \" does not exist\");\n    }\n    if (line.endsWith(\"Too many levels of symbolic links\")) {\n      throw new IOException(\"Possible cyclic loop while following symbolic\" +\n          \" link \" + original);\n    }\n    // 6,symbolic link,6,1373584236,1373584236,lrwxrwxrwx,andrew,andrew,`link' -> `target'\n    // OR\n    // 6,symbolic link,6,1373584236,1373584236,lrwxrwxrwx,andrew,andrew,'link' -> 'target'\n    StringTokenizer tokens = new StringTokenizer(line, \",\");\n    try {\n      long length = Long.parseLong(tokens.nextToken());\n      boolean isDir = tokens.nextToken().equalsIgnoreCase(\"directory\") ? true\n          : false;\n      // Convert from seconds to milliseconds\n      long modTime = Long.parseLong(tokens.nextToken())*1000;\n      long accessTime = Long.parseLong(tokens.nextToken())*1000;\n      String octalPerms = tokens.nextToken();\n      // FreeBSD has extra digits beyond 4, truncate them","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Stat.java#L103-L139","documentation":"Thrown in Stat.parseExecResult when the stat output line ends with 'No such file or directory' or 'Not a directory', i.e. the shell command failed with ENOENT or ENOTDIR. Stat translates those well-known stderr strings into FileNotFoundException with the original path, giving callers the standard 'file does not exist' semantics.","triggerScenarios":"new Stat(path, ...).getFileStatus() where path does not exist, or where a parent component of the path is a regular file (ENOTDIR, e.g. /somefile/sub). Also when a file is deleted between an exists() check and the stat call (TOCTOU).","commonSituations":"Cleaning up temp paths that another process already removed; a path typo where a file name is used as a directory component; migration scripts statting paths from an old layout.","solutions":["Verify the path and each parent component: the file must exist and no parent may be a plain file","Handle FileNotFoundException as a non-fatal 'already gone' case in cleanup code","For pure existence checks prefer fs.exists(p) or Files.exists instead of full stat parsing"],"exampleFix":"// before\nFileStatus st = new Stat(path, false, shell).getFileStatus();\n\n// after\njava.nio.file.Path p = java.nio.file.Paths.get(path.toString());\nif (!java.nio.file.Files.exists(p)) {\n  throw new java.io.FileNotFoundException(path.toString());\n}","handlingStrategy":"validation","validationCode":"java.nio.file.Path nio = java.nio.file.Paths.get(path.toString());\nif (!java.nio.file.Files.exists(nio)) {\n  throw new java.io.FileNotFoundException(path.toString());\n}\nFileStatus st = new Stat(path, false, shell).getFileStatus();","typeGuard":null,"tryCatchPattern":"try {\n  st = stat.getFileStatus();\n} catch (java.io.FileNotFoundException e) {\n  // already gone: benign for cleanup loops\n  return;\n}","preventionTips":["Use exists() checks for pure existence queries instead of full stat","Treat FileNotFoundException as expected in idempotent cleanup code, not as a fatal error"],"tags":["hadoop","stat","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}