{"record":{"id":"e34e9458934a6a9f","repo":"apache/hadoop","slug":"not-a-file-in","errorCode":null,"errorMessage":"{} : not a file in {}","messagePattern":"(.+?) : not a file in (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/HarFileSystem.java","lineNumber":684,"sourceCode":"  /**\n   * @return null since no checksum algorithm is implemented.\n   */\n  @Override\n  public FileChecksum getFileChecksum(Path f, long length) {\n    return null;\n  }\n\n  /**\n   * Returns a har input stream which fakes end of \n   * file. It reads the index files to get the part \n   * file name and the size and start of the file.\n   */\n  @Override\n  public FSDataInputStream open(Path f, int bufferSize) throws IOException {\n    // get the fs DataInputStream for the underlying file\n    HarStatus hstatus = getFileHarStatus(f);\n    if (hstatus.isDir()) {\n      throw new FileNotFoundException(f + \" : not a file in \" +\n                archivePath);\n    }\n    return new HarFSDataInputStream(fs, new Path(archivePath, \n        hstatus.getPartName()),\n        hstatus.getStartIndex(), hstatus.getLength(), bufferSize);\n  }\n\n  @Override\n  protected PathHandle createPathHandle(FileStatus stat, HandleOpt... opts) {\n    // har consistency managed through metadata cache\n    // could extend HarMetaData to track more explicitly\n    throw new UnsupportedOperationException();\n  }\n\n  @Override\n  public FSDataInputStream open(PathHandle fd, int bufferSize)\n      throws IOException {\n    throw new UnsupportedOperationException();","sourceCodeStart":666,"sourceCodeEnd":702,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/HarFileSystem.java#L666-L702","documentation":"open(Path, int) found a HarStatus entry, but it is a directory (hstatus.isDir()). Directories in a har are index-only constructs with no byte range in the part files, so no input stream can be produced and open fails with FileNotFoundException ('not a file').","triggerScenarios":"fs.open(dir) on any archive directory — the archive root har://.../data.har/ itself or a directory entry returned by listStatus; also generic code that opens user-supplied paths without a type check.","commonSituations":"Traversal code that calls open on every listStatus result, including directories; CLI tools whose 'input file' argument resolves to a directory inside an archive.","solutions":["Check fs.getFileStatus(p).isDirectory() before open and descend with listStatus instead","If you meant to read members, list the directory and open each file entry","Validate user-supplied paths up front with getFileStatus and fail with a clear message"],"exampleFix":"// before\nFSDataInputStream in = fs.open(dirPathInHar); // FileNotFoundException: not a file\n\n// after\nif (fs.getFileStatus(dirPathInHar).isDirectory()) {\n  for (FileStatus s : fs.listStatus(dirPathInHar)) {\n    if (s.isFile()) read(fs.open(s.getPath()));\n  }\n}","handlingStrategy":"validation","validationCode":"FileStatus st = fs.getFileStatus(p);\nif (st.isDirectory()) {\n  throw new IllegalArgumentException(p + \" is a directory; open() requires a file in the archive\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  in = fs.open(p, bufferSize);\n} catch (FileNotFoundException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"not a file\")) {\n    // p is a directory: descend with listStatus instead\n  }\n  throw e;\n}","preventionTips":["Check getFileStatus(...).isDirectory() before every open on user-supplied paths","When iterating listStatus results, filter with isFile() before opening","Validate inputs at the CLI/config boundary, not deep in read loops"],"tags":["hadoop","har-filesystem","is-a-directory","file-not-found"],"backgroundTag":"open-on-directory","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}