apache/hadoop · error · FileNotFoundException
Source '{srcFile}' does not exist
Error message
Source '{srcFile}' does not exist What it means
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.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java:1333
* @param srcFile an existing file to copy, must not be {@code null}
* @param destFile the new file, must not be {@code null}
* @param preserveFileDate true if the file date of the copy
* should be the same as the original
*
* @throws NullPointerException if source or destination is {@code null}
* @throws IOException if source or destination is invalid
* @throws IOException if an IO error occurs during copying
*/
public static void nativeCopyFileUnbuffered(File srcFile, File destFile,
boolean preserveFileDate) throws IOException {
if (srcFile == null) {
throw new NullPointerException("Source must not be null");
}
if (destFile == null) {
throw new NullPointerException("Destination must not be null");
}
if (srcFile.exists() == false) {
throw new FileNotFoundException("Source '" + srcFile + "' does not exist");
}
if (srcFile.isDirectory()) {
throw new IOException("Source '" + srcFile + "' exists but is a directory");
}
if (srcFile.getCanonicalPath().equals(destFile.getCanonicalPath())) {
throw new IOException("Source '" + srcFile + "' and destination '" +
destFile + "' are the same");
}
File parentFile = destFile.getParentFile();
if (parentFile != null) {
if (!parentFile.mkdirs() && !parentFile.isDirectory()) {
throw new IOException("Destination '" + parentFile
+ "' directory cannot be created");
}
}
if (destFile.exists()) {
if (FileUtil.canWrite(destFile) == false) {
throw new IOException("Destination '" + destFileView on GitHub (pinned to 2add963021)
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
Example fix
// before Storage.nativeCopyFileUnbuffered(new File(path), dst, true); // after File src = new File(path).getAbsoluteFile(); if (!src.isFile()) throw new FileNotFoundException(src + " missing; parent readable?"); Storage.nativeCopyFileUnbuffered(src, dst, true);
Defensive patterns
Strategy: validation
Validate before calling
File abs = srcFile == null ? null : srcFile.getAbsoluteFile();
if (abs == null || !Files.isRegularFile(abs.toPath())) {
throw new FileNotFoundException("copy source missing or unreadable: " + abs);
} Type guard
static boolean isReadableRegularFile(File f) {
return f != null && f.isFile() && f.canRead();
} Try / catch
try {
Storage.nativeCopyFileUnbuffered(src, dst, true);
} catch (FileNotFoundException e) {
// re-resolve the source (producer may have failed) and give a path-absolute error
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- %s does not exist or is not file.
- Source '{srcFile}' exists but is a directory
- Destination '{parentFile}' directory cannot be created
- Destination '{destFile}' exists but is read-only
- %s not found: %s
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/2e74f19aca17912d.
Report an issue: GitHub.