{"record":{"id":"11c284270604bc1c","repo":"apache/hadoop","slug":"file-p-does-not-exist","errorCode":null,"errorMessage":"File \" + p + \" does not exist","messagePattern":"File \" \\+ p \\+ \" 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":1220,"sourceCode":" \n  /**\n   * Sets the {@link Path}'s last modified time and last access time to\n   * the given valid times.\n   *\n   * @param mtime the modification time to set (only if no less than zero).\n   * @param atime the access time to set (only if no less than zero).\n   * @throws IOException if setting the times fails.\n   */\n  @Override\n  public void setTimes(Path p, long mtime, long atime) throws IOException {\n    try {\n      BasicFileAttributeView view = Files.getFileAttributeView(\n          pathToFile(p).toPath(), BasicFileAttributeView.class);\n      FileTime fmtime = (mtime >= 0) ? FileTime.fromMillis(mtime) : null;\n      FileTime fatime = (atime >= 0) ? FileTime.fromMillis(atime) : null;\n      view.setTimes(fmtime, fatime, null);\n    } catch (NoSuchFileException e) {\n      throw new FileNotFoundException(\"File \" + p + \" does not exist\");\n    }\n  }\n\n  /**\n   * Hook to implement support for {@link PathHandle} operations.\n   * @param stat Referent in the target FileSystem\n   * @param opts Constraints that determine the validity of the\n   *            {@link PathHandle} reference.\n   */\n  protected PathHandle createPathHandle(FileStatus stat,\n      Options.HandleOpt... opts) {\n    if (stat.isDirectory() || stat.isSymlink()) {\n      throw new IllegalArgumentException(\"PathHandle only available for files\");\n    }\n    String authority = stat.getPath().toUri().getAuthority();\n    if (authority != null && !authority.equals(\"file://\")) {\n      throw new IllegalArgumentException(\"Wrong FileSystem: \" + stat.getPath());\n    }","sourceCodeStart":1202,"sourceCodeEnd":1238,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java#L1202-L1238","documentation":"RawLocalFileSystem.setTimes(Path, mtime, atime) sets timestamps through the NIO BasicFileAttributeView; when the view operation fails with NoSuchFileException (view resolution or setTimes on a missing file), it is translated to FileNotFoundException('File ... does not exist'). Negative mtime/atime values mean 'leave unchanged', so they never cause this error.","triggerScenarios":"Calling fs.setTimes(p, mtime, a) on a local path that does not exist: touching output files that were moved/committed already, distcp preservation touching deleted files, or races where a cleaner removed the file before the timestamp stage.","commonSituations":"DistCp -p preserving times on files deleted mid-copy by a concurrent job, post-processing hooks touching files a committer already renamed, typo'd paths, or unmounted volumes in containers.","solutions":["Check existence right before setTimes: if (fs.exists(p)) fs.setTimes(p, mtime, atime);","Fix the stale path in the job/config if files legitimately moved.","Catch FileNotFoundException and skip when operating on best-effort metadata of concurrently-changing trees.","Pass -1 for times you do not want to change instead of fabricated values."],"exampleFix":"// before\nfs.setTimes(outFile, mtime, atime); // file renamed by committer -> FNF\n\n// after\nif (fs.exists(outFile)) {\n  fs.setTimes(outFile, mtime, atime);\n} else {\n  LOG.debug(\"Skipping setTimes; {} no longer exists\", outFile);\n}","handlingStrategy":"try-catch","validationCode":"if (fs.exists(p)) {\n  fs.setTimes(p, mtime >= 0 ? mtime : -1, atime >= 0 ? atime : -1);\n} else {\n  LOG.debug(\"setTimes skipped; {} does not exist\", p);\n}","typeGuard":null,"tryCatchPattern":"try {\n  fs.setTimes(p, mtime, atime);\n} catch (FileNotFoundException e) {\n  // metadata preservation is best-effort on concurrently changing trees\n  LOG.debug(\"{} gone before setTimes\", p);\n}","preventionTips":["Guard metadata-preserving steps (setTimes/setOwner) with exists() or catch FNF as best-effort.","Pass -1 for timestamps you do not intend to change.","Run timestamp preservation before committers rename/move files."],"tags":["hadoop","local-filesystem","set-times","file-not-found","filenotfoundexception","metadata"],"backgroundTag":"file-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}