{"record":{"id":"3031cbd99ea61a17","repo":"apache/hadoop","slug":"path-points-to-dir-not-a-file-3031cb","errorCode":null,"errorMessage":"Path points to dir not a file","messagePattern":"Path points to dir not a file","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java","lineNumber":1070,"sourceCode":"    public BlockLocation[] getFileBlockLocations(final Path f, final long start,\n        final long len) throws FileNotFoundException, IOException {\n      // When application calls listFiles on internalDir, it would return\n      // RemoteIterator from InternalDirOfViewFs. If there is a fallBack, there\n      // is a chance of files exists under that internalDir in fallback.\n      // Iterator#next will call getFileBlockLocations with that files. So, we\n      // should return getFileBlockLocations on fallback. See HDFS-15532.\n      if (!InodeTree.SlashPath.equals(f) && this.fsState\n          .getRootFallbackLink() != null) {\n        AbstractFileSystem linkedFallbackFs =\n            this.fsState.getRootFallbackLink().getTargetFileSystem();\n        Path parent = Path.getPathWithoutSchemeAndAuthority(\n            new Path(theInternalDir.fullPath));\n        Path pathToFallbackFs = new Path(parent, f.getName());\n        return linkedFallbackFs\n            .getFileBlockLocations(pathToFallbackFs, start, len);\n      }\n      checkPathIsSlash(f);\n      throw new FileNotFoundException(\"Path points to dir not a file\");\n    }\n\n    @Override\n    public FileChecksum getFileChecksum(final Path f)\n        throws FileNotFoundException, IOException {\n      checkPathIsSlash(f);\n      throw new FileNotFoundException(\"Path points to dir not a file\");\n    }\n\n    @Override\n    public FileStatus getFileStatus(final Path f) throws IOException {\n      checkPathIsSlash(f);\n      return new FileStatus(0, true, 0, 0, creationTime, creationTime,\n          PERMISSION_555, ugi.getShortUserName(), ugi.getPrimaryGroupName(),\n          new Path(theInternalDir.fullPath).makeQualified(\n              myUri, null));\n    }\n","sourceCodeStart":1052,"sourceCodeEnd":1088,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java#L1052-L1088","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Only call getFileBlockLocations on file paths produced by listStatus/open (files always resolve to a mounted FS)","Configure fs.viewfs.mounttable.<n>.linkFallback so internal-dir children delegate to a real cluster","Guard with FileStatus.isFile() before requesting block locations"],"exampleFix":"// before\nBlockLocation[] bl = fc.getFileBlockLocations(fc.getFileStatus(p), 0, len); // p = \"/\"\n\n// after\nFileStatus st = fc.getFileStatus(p);\nif (!st.isFile()) { return new BlockLocation[0]; }\nBlockLocation[] bl = fc.getFileBlockLocations(st, 0, len);","handlingStrategy":"validation","validationCode":"FileStatus st = fs.getFileStatus(p);\nif (!st.isFile()) {\n  // directory or virtual mount-table dir: no block locations\n  return new BlockLocation[0];\n}\nBlockLocation[] locs = fs.getFileBlockLocations(st, 0, st.getLen());","typeGuard":null,"tryCatchPattern":"try {\n  locs = fc.getFileBlockLocations(status, start, len);\n} catch (FileNotFoundException fnfe) {\n  if (fnfe.getMessage().equals(\"Path points to dir not a file\")) locs = new BlockLocation[0];\n  else throw fnfe;\n}","preventionTips":["InputFormats should derive splits from listed files, never pass dirs to getFileBlockLocations","Configure linkFallback so internal-dir children delegate to a real cluster (HDFS-15532 behavior)"],"tags":["viewfs","mount-table","block-locations","file-not-found","hadoop-common"],"backgroundTag":"path-is-directory-not-file","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}