apache/hadoop · error · FileNotFoundException
File " + p + " does not exist
Error message
File " + p + " does not exist
What it means
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.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java:1220
/**
* Sets the {@link Path}'s last modified time and last access time to
* the given valid times.
*
* @param mtime the modification time to set (only if no less than zero).
* @param atime the access time to set (only if no less than zero).
* @throws IOException if setting the times fails.
*/
@Override
public void setTimes(Path p, long mtime, long atime) throws IOException {
try {
BasicFileAttributeView view = Files.getFileAttributeView(
pathToFile(p).toPath(), BasicFileAttributeView.class);
FileTime fmtime = (mtime >= 0) ? FileTime.fromMillis(mtime) : null;
FileTime fatime = (atime >= 0) ? FileTime.fromMillis(atime) : null;
view.setTimes(fmtime, fatime, null);
} catch (NoSuchFileException e) {
throw new FileNotFoundException("File " + p + " does not exist");
}
}
/**
* Hook to implement support for {@link PathHandle} operations.
* @param stat Referent in the target FileSystem
* @param opts Constraints that determine the validity of the
* {@link PathHandle} reference.
*/
protected PathHandle createPathHandle(FileStatus stat,
Options.HandleOpt... opts) {
if (stat.isDirectory() || stat.isSymlink()) {
throw new IllegalArgumentException("PathHandle only available for files");
}
String authority = stat.getPath().toUri().getAuthority();
if (authority != null && !authority.equals("file://")) {
throw new IllegalArgumentException("Wrong FileSystem: " + stat.getPath());
}View on GitHub (pinned to 2add963021)
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.
Example fix
// before
fs.setTimes(outFile, mtime, atime); // file renamed by committer -> FNF
// after
if (fs.exists(outFile)) {
fs.setTimes(outFile, mtime, atime);
} else {
LOG.debug("Skipping setTimes; {} no longer exists", outFile);
} Defensive patterns
Strategy: try-catch
Validate before calling
if (fs.exists(p)) {
fs.setTimes(p, mtime >= 0 ? mtime : -1, atime >= 0 ? atime : -1);
} else {
LOG.debug("setTimes skipped; {} does not exist", p);
} Try / catch
try {
fs.setTimes(p, mtime, atime);
} catch (FileNotFoundException e) {
// metadata preservation is best-effort on concurrently changing trees
LOG.debug("{} gone before setTimes", p);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
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
- File " + f + " not found
- File " + f + " does not exist
- Parent directory doesn't exist: {}
- key + ": No such file or directory."
- No such file or directory '{}'
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/11c284270604bc1c.
Report an issue: GitHub.