apache/hadoop · error · FileNotFoundException

File {file} does not exist.

Error message

File {file} does not exist.

What it means

getFileStatus lists the parent directory via FTP LIST and matches entries by exact name; if the listing succeeds but no entry matches the path's final component, FileNotFoundException is thrown — the standard missing-file signal that open(), exists(), delete() and friends propagate.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ftp/FTPFileSystem.java:542

      boolean isDir = true;
      int blockReplication = 1;
      long blockSize = DEFAULT_BLOCK_SIZE; // Block Size not known.
      long modTime = -1; // Modification time of root dir not known.
      Path root = new Path("/");
      return new FileStatus(length, isDir, blockReplication, blockSize,
          modTime, this.makeQualified(root));
    }
    String pathName = parentPath.toUri().getPath();
    FTPFile[] ftpFiles = client.listFiles(pathName);
    if (ftpFiles != null) {
      for (FTPFile ftpFile : ftpFiles) {
        if (ftpFile.getName().equals(file.getName())) { // file found in dir
          fileStat = getFileStatus(ftpFile, parentPath);
          break;
        }
      }
      if (fileStat == null) {
        throw new FileNotFoundException("File " + file + " does not exist.");
      }
    } else {
      throw new FileNotFoundException("File " + file + " does not exist.");
    }
    return fileStat;
  }

  /**
   * Convert the file information in FTPFile to a {@link FileStatus} object. *
   * 
   * @param ftpFile
   * @param parentPath
   * @return FileStatus
   */
  private FileStatus getFileStatus(FTPFile ftpFile, Path parentPath) {
    long length = ftpFile.getSize();
    boolean isDir = ftpFile.isDirectory();
    int blockReplication = 1;

View on GitHub (pinned to 2add963021)

Solutions

  1. Check fs.exists(path) (implemented as a getFileStatus that swallows exactly this exception) before access
  2. Log the exact path string (with delimiters) when paths are built dynamically to expose whitespace/case issues
  3. If a race deleted the file, decide explicitly between skipping the task and failing it
Defensive patterns

Strategy: validation

Validate before calling

if (!fs.exists(path)) {
  // skip or fail explicitly instead of letting open()/delete() throw
  LOG.warn("Input missing: {}", path);
  return;
}
FSDataInputStream in = fs.open(path);

Try / catch

try {
  st = fs.getFileStatus(path);
} catch (FileNotFoundException e) {
  // expected for globs/optional inputs: skip or count-and-report
  return null;
}

Prevention

When it happens

Trigger: fs.getFileStatus/open/delete on a path whose final component does not exist in its parent; filename case mismatch (FTP names are case-sensitive); trailing spaces or characters lost when constructing paths.

Common situations: Stale paths after files were renamed/removed; glob results consumed after another process deleted the files; case-sensitivity mismatches between client and server platforms.

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


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/c1e71289e4835d02. Report an issue: GitHub.