apache/hadoop · error · FileNotFoundException

Path is not a file, %s

Error message

Path is not a file, %s

What it means

getFileChecksum(f, length) throws FileNotFoundException("Path is not a file, %s") when the target is a directory. The comment notes this is for HDFS compatibility: HDFS also reports checksum requests on directories as FileNotFoundException rather than a type error.

Source

Thrown at hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/RawFileSystem.java:663

  public ObjectStorage storage() {
    return storage;
  }

  public ExecutorService uploadThreadPool() {
    return uploadThreadPool;
  }

  /**
   * @return null if checksum is not supported.
   */
  @Override
  public FileChecksum getFileChecksum(Path f, long length) throws IOException {
    Preconditions.checkArgument(length >= 0);

    RawFileStatus fileStatus = innerFileStatus(f);
    if (fileStatus.isDirectory()) {
      // Compatible with HDFS
      throw new FileNotFoundException(String.format("Path is not a file, %s", f));
    }
    if (!getConf().getBoolean(ConfKeys.FS_CHECKSUM_ENABLED.key(storage.scheme()),
        ConfKeys.FS_CHECKSUM_ENABLED_DEFAULT)) {
      return null;
    }

    ChecksumInfo csInfo = storage.checksumInfo();
    return new TosChecksum(csInfo.algorithm(), fileStatus.checksum());
  }

  @Override
  public String getCanonicalServiceName() {
    return null;
  }

  @Override
  public void setXAttr(Path path, String name, byte[] value, EnumSet<XAttrSetFlag> flag)
      throws IOException {

View on GitHub (pinned to 2add963021)

Solutions

  1. Filter to files before requesting checksums: skip entries where getFileStatus().isDirectory()
  2. If checksums are disabled entirely (fs.tos.checksum.enabled=false) the call returns null for files -- treat that as 'no checksum', not an error
  3. Pass a non-negative length

Example fix

// before
for (FileStatus st : fs.listStatus(dir)) {
  FileChecksum cs = fs.getFileChecksum(st.getPath(), 1024); // throws on directories
}

// after
for (FileStatus st : fs.listStatus(dir)) {
  if (!st.isDirectory()) { FileChecksum cs = fs.getFileChecksum(st.getPath(), 1024); }
}
Defensive patterns

Strategy: validation

Validate before calling

FileStatus st = fs.getFileStatus(f);
if (!st.isFile()) return null; // HDFS parity: directories have no checksum
FileChecksum cs = fs.getFileChecksum(f, Math.max(0, length));

Try / catch

try { cs = fs.getFileChecksum(f, length); }
catch (FileNotFoundException e) {
  if (fs.getFileStatus(f).isDirectory()) { /* skip dirs */ } else throw e;
}

Prevention

When it happens

Trigger: fs.getFileChecksum(dirPath, length) where innerFileStatus(dirPath).isDirectory() is true; also note length must be >= 0 (Preconditions.checkArgument) or you get IllegalArgumentException instead.

Common situations: Utilities that walk a tree and request checksums for every listStatus() entry without filtering; verification scripts assuming checksum failure means corruption hitting a directory entry; distcp-style compare steps.

Related errors


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