{"record":{"id":"9faaa7c949da3c3b","repo":"apache/hadoop","slug":"path-points-to-dir-not-a-file","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/ViewFileSystem.java","lineNumber":1524,"sourceCode":"\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(fs.getPath()) && this.fsState\n          .getRootFallbackLink() != null) {\n        FileSystem linkedFallbackFs =\n            this.fsState.getRootFallbackLink().getTargetFileSystem();\n        Path parent = Path.getPathWithoutSchemeAndAuthority(\n            new Path(theInternalDir.fullPath));\n        Path pathToFallbackFs = new Path(parent, fs.getPath().getName());\n        return linkedFallbackFs\n            .getFileBlockLocations(pathToFallbackFs, start, len);\n      }\n\n      checkPathIsSlash(fs.getPath());\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(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, ROOT_PATH));\n    }\n","sourceCodeStart":1506,"sourceCodeEnd":1542,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java#L1506-L1542","documentation":"ViewFileSystem.InternalDir.getFileBlockLocations(...) serves paths that resolve to mount-table internal directories. If the path is exactly the internal dir (checkPathIsSlash) and no root fallback link exists to forward to, the location of a 'file' cannot be computed because the path is a directory node of the mount table; it throws FileNotFoundException('Path points to dir not a file').","triggerScenarios":"Split computation (FileInputFormat/FileSplit) or any getFileBlockLocations call on a viewfs path that is an internal mount-table directory, e.g. '/data' when only /data/hdfs is mounted; distcp or readers asking block locations for the parent of mounts.","commonSituations":"MapReduce/Spark input paths set to a viewfs internal dir without linkMergeSlash; recursive listings where a parent dir is fed to a block-location API; federation migrations where the old input root became a virtual directory.","solutions":["Point the input path at the mounted child directory or at files beneath it","Add fs.viewfs.mounttable.default.linkMergeSlash or a linkFallback for that internal dir so locations delegate to a real file system","List the internal dir and recurse into mounted children instead of asking locations for the dir itself","Validate with getFileStatus(path).isDirectory() before requesting block locations and skip directories"],"exampleFix":"// before\nFileStatus st = fs.getFileStatus(new Path(\"/data\"));\nBlockLocation[] locs = fs.getFileBlockLocations(st, 0, st.getLen()); // dir -> throws\n\n// after\nif (fs.getFileStatus(new Path(\"/data\")).isDirectory()) {\n  for (FileStatus child : fs.listStatus(new Path(\"/data\"))) {\n    if (child.isFile()) { /* ask locations per file */ }\n  }\n}","handlingStrategy":"validation","validationCode":"// Only request block locations for regular files\nFileStatus st = fs.getFileStatus(p);\nif (st.isDirectory()) {\n  throw new IllegalArgumentException(p + \" is a directory; no block locations\");\n}\nBlockLocation[] locs = fs.getFileBlockLocations(st, 0, st.getLen());","typeGuard":null,"tryCatchPattern":"try {\n  locs = fs.getFileBlockLocations(st, start, len);\n} catch (FileNotFoundException e) {\n  // mount-table internal dir: recurse into mounted children instead\n  locs = new BlockLocation[0];\n}","preventionTips":["Set input paths to mounted directories or files, never virtual parents","Filter listings with isFile() before split computation","Add linkFallback/linkMergeSlash when the layout requires delegating whole subtrees"],"tags":["viewfs","hadoop","block-locations","inputformat","mount-table"],"backgroundTag":"path-points-to-directory","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}