{"record":{"id":"2e74f19aca17912d","repo":"apache/hadoop","slug":"source-srcfile-does-not-exist","errorCode":null,"errorMessage":"Source '{srcFile}' does not exist","messagePattern":"Source '(.+?)' does not exist","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java","lineNumber":1333,"sourceCode":"   * @param srcFile  an existing file to copy, must not be {@code null}\n   * @param destFile  the new file, must not be {@code null}\n   * @param preserveFileDate  true if the file date of the copy\n   *  should be the same as the original\n   *\n   * @throws NullPointerException if source or destination is {@code null}\n   * @throws IOException if source or destination is invalid\n   * @throws IOException if an IO error occurs during copying\n   */\n  public static void nativeCopyFileUnbuffered(File srcFile, File destFile,\n      boolean preserveFileDate) throws IOException {\n    if (srcFile == null) {\n      throw new NullPointerException(\"Source must not be null\");\n    }\n    if (destFile == null) {\n      throw new NullPointerException(\"Destination must not be null\");\n    }\n    if (srcFile.exists() == false) {\n      throw new FileNotFoundException(\"Source '\" + srcFile + \"' does not exist\");\n    }\n    if (srcFile.isDirectory()) {\n      throw new IOException(\"Source '\" + srcFile + \"' exists but is a directory\");\n    }\n    if (srcFile.getCanonicalPath().equals(destFile.getCanonicalPath())) {\n      throw new IOException(\"Source '\" + srcFile + \"' and destination '\" +\n          destFile + \"' are the same\");\n    }\n    File parentFile = destFile.getParentFile();\n    if (parentFile != null) {\n      if (!parentFile.mkdirs() && !parentFile.isDirectory()) {\n        throw new IOException(\"Destination '\" + parentFile\n            + \"' directory cannot be created\");\n      }\n    }\n    if (destFile.exists()) {\n      if (FileUtil.canWrite(destFile) == false) {\n        throw new IOException(\"Destination '\" + destFile","sourceCodeStart":1315,"sourceCodeEnd":1351,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java#L1315-L1351","documentation":"Guard clause of Storage.nativeCopyFileUnbuffered: srcFile.exists() returned false, so the copy aborts with FileNotFoundException before NativeIO is invoked. exists() can also return false when the parent directory is unreadable, not only when the file is absent.","triggerScenarios":"Mistyped or wrong source path; the file was deleted between path resolution and the copy call; the parent directory denies search permission so exists() observes nothing; a relative path resolved against an unexpected working directory.","commonSituations":"Checkpoint/bootstrap code copying an fsimage whose producing step failed silently; permission changes on storage dirs after setup; scripts passing relative paths from a different cwd.","solutions":["Log or print the absolute source path and verify it on disk","Check execute/search permission on every parent directory (exists() is false on unreadable parents)","If a race deleted the file, re-run the producing step (e.g. wait for the checkpoint to finish) before copying","Use absolute paths at the API boundary"],"exampleFix":"// before\nStorage.nativeCopyFileUnbuffered(new File(path), dst, true);\n// after\nFile src = new File(path).getAbsoluteFile();\nif (!src.isFile()) throw new FileNotFoundException(src + \" missing; parent readable?\");\nStorage.nativeCopyFileUnbuffered(src, dst, true);","handlingStrategy":"validation","validationCode":"File abs = srcFile == null ? null : srcFile.getAbsoluteFile();\nif (abs == null || !Files.isRegularFile(abs.toPath())) {\n  throw new FileNotFoundException(\"copy source missing or unreadable: \" + abs);\n}","typeGuard":"static boolean isReadableRegularFile(File f) {\n  return f != null && f.isFile() && f.canRead();\n}","tryCatchPattern":"try {\n  Storage.nativeCopyFileUnbuffered(src, dst, true);\n} catch (FileNotFoundException e) {\n  // re-resolve the source (producer may have failed) and give a path-absolute error\n}","preventionTips":["Verify the producing step (checkpoint, export) succeeded before copying its output","Prefer absolute paths at library boundaries","Remember unreadable parents make exists() false - check parent permissions too"],"tags":["hdfs","file-copy","file-not-found","filesystem"],"backgroundTag":"file-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}