apache/hadoop · error · FileNotFoundException

Path points to dir not a file

Error message

Path points to dir not a file

What it means

InternalDirOfViewFs.getFileBlockLocations cannot answer for a virtual directory. If the path is not "/" and a root fallback link exists, it delegates to the fallback FileSystem (HDFS-15532); otherwise checkPathIsSlash guarantees f=="/" and the method throws FileNotFoundException("Path points to dir not a file"). Block locations are a per-file property of the backing cluster, which a mount-table dir does not have.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java:1070

    public BlockLocation[] getFileBlockLocations(final Path f, final long start,
        final long len) throws FileNotFoundException, IOException {
      // When application calls listFiles on internalDir, it would return
      // RemoteIterator from InternalDirOfViewFs. If there is a fallBack, there
      // is a chance of files exists under that internalDir in fallback.
      // Iterator#next will call getFileBlockLocations with that files. So, we
      // should return getFileBlockLocations on fallback. See HDFS-15532.
      if (!InodeTree.SlashPath.equals(f) && this.fsState
          .getRootFallbackLink() != null) {
        AbstractFileSystem linkedFallbackFs =
            this.fsState.getRootFallbackLink().getTargetFileSystem();
        Path parent = Path.getPathWithoutSchemeAndAuthority(
            new Path(theInternalDir.fullPath));
        Path pathToFallbackFs = new Path(parent, f.getName());
        return linkedFallbackFs
            .getFileBlockLocations(pathToFallbackFs, start, len);
      }
      checkPathIsSlash(f);
      throw new FileNotFoundException("Path points to dir not a file");
    }

    @Override
    public FileChecksum getFileChecksum(final Path f)
        throws FileNotFoundException, IOException {
      checkPathIsSlash(f);
      throw new FileNotFoundException("Path points to dir not a file");
    }

    @Override
    public FileStatus getFileStatus(final Path f) throws IOException {
      checkPathIsSlash(f);
      return new FileStatus(0, true, 0, 0, creationTime, creationTime,
          PERMISSION_555, ugi.getShortUserName(), ugi.getPrimaryGroupName(),
          new Path(theInternalDir.fullPath).makeQualified(
              myUri, null));
    }

View on GitHub (pinned to 2add963021)

Solutions

  1. Only call getFileBlockLocations on file paths produced by listStatus/open (files always resolve to a mounted FS)
  2. Configure fs.viewfs.mounttable.<n>.linkFallback so internal-dir children delegate to a real cluster
  3. Guard with FileStatus.isFile() before requesting block locations

Example fix

// before
BlockLocation[] bl = fc.getFileBlockLocations(fc.getFileStatus(p), 0, len); // p = "/"

// after
FileStatus st = fc.getFileStatus(p);
if (!st.isFile()) { return new BlockLocation[0]; }
BlockLocation[] bl = fc.getFileBlockLocations(st, 0, len);
Defensive patterns

Strategy: validation

Validate before calling

FileStatus st = fs.getFileStatus(p);
if (!st.isFile()) {
  // directory or virtual mount-table dir: no block locations
  return new BlockLocation[0];
}
BlockLocation[] locs = fs.getFileBlockLocations(st, 0, st.getLen());

Try / catch

try {
  locs = fc.getFileBlockLocations(status, start, len);
} catch (FileNotFoundException fnfe) {
  if (fnfe.getMessage().equals("Path points to dir not a file")) locs = new BlockLocation[0];
  else throw fnfe;
}

Prevention

When it happens

Trigger: InputFormat split computation (getSplits) or any fs.getFileBlockLocations(dirPath, 0, len) invoked on a viewfs internal directory such as viewfs:///; distCp/file-transfer code asking for locations of a listed directory that resolved to the internal dir.

Common situations: MapReduce/Spark jobs whose input path is a mount-table container dir; code reused from plain HDFS that calls getFileBlockLocations before checking isFile; deployments without a root fallback link.

Related errors


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