{"record":{"id":"93cb115d38b28925","repo":"apache/hadoop","slug":"is-a-directory-93cb11","errorCode":null,"errorMessage":"'{}' is a directory","messagePattern":"'(.+?)' is a directory","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-cos/src/main/java/org/apache/hadoop/fs/cosn/CosNFileSystem.java","lineNumber":592,"sourceCode":"      if (LOG.isDebugEnabled()) {\n        LOG.debug(\"Make directory: [{}] in COS.\", f);\n      }\n\n      String folderPath = pathToKey(makeAbsolute(f));\n      if (!folderPath.endsWith(PATH_DELIMITER)) {\n        folderPath += PATH_DELIMITER;\n      }\n      store.storeEmptyFile(folderPath);\n    }\n    return true;\n  }\n\n  @Override\n  public FSDataInputStream open(Path f, int bufferSize) throws IOException {\n    FileStatus fs = getFileStatus(f); // will throw if the file doesn't\n    // exist\n    if (fs.isDirectory()) {\n      throw new FileNotFoundException(\"'\" + f + \"' is a directory\");\n    }\n    LOG.info(\"Open the file: [{}] for reading.\", f);\n    Path absolutePath = makeAbsolute(f);\n    String key = pathToKey(absolutePath);\n    long fileSize = store.getFileLength(key);\n    return new FSDataInputStream(new BufferedFSInputStream(\n        new CosNInputStream(this.getConf(), store, statistics, key, fileSize,\n            this.boundedIOThreadPool), bufferSize));\n  }\n\n  @Override\n  public boolean rename(Path src, Path dst) throws IOException {\n    LOG.debug(\"Rename source path: [{}] to dest path: [{}].\", src, dst);\n\n    // Renaming the root directory is not allowed\n    if (src.isRoot()) {\n      LOG.debug(\"Cannot rename the root directory of a filesystem.\");\n      return false;","sourceCodeStart":574,"sourceCodeEnd":610,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-cos/src/main/java/org/apache/hadoop/fs/cosn/CosNFileSystem.java#L574-L610","documentation":"open() stats the path and refuses directories with FileNotFoundException(\"'<path>' is a directory\"). COS has no directory payload to read, so opening a directory key — including the 0-byte marker objects CosN itself creates — is treated as 'nothing to read', mirroring LocalFileSystem behavior.","triggerScenarios":"fs.open(dirPath); opening a path that exists only as an implicit directory (common prefixes derived from children); hadoop fs -cat on a directory; code that globs a pattern and open()s every result without filtering.","commonSituations":"Glob 'cosn://bucket/*' then open each status including directories; passing a directory to a reader that expects a file; trailing-slash confusion where a directory path is handed to open unchanged.","solutions":["Filter glob results: only open statuses where isFile() is true.","If a file was expected, inspect getFileStatus(p) — the path is actually a directory.","Use fs.listStatus(dir) to enumerate children instead of open()."],"exampleFix":"// before\nfor (FileStatus s : fs.globStatus(new Path('/in/*'))) {\n  FSDataInputStream in = fs.open(s.getPath()); // throws on directories\n}\n\n// after\nfor (FileStatus s : fs.globStatus(new Path('/in/*'))) {\n  if (s.isFile()) {\n    FSDataInputStream in = fs.open(s.getPath());\n  }\n}","handlingStrategy":"validation","validationCode":"FileStatus st = fs.getFileStatus(p);\nif (st.isDirectory()) {\n  for (FileStatus child : fs.listStatus(p)) { /* enumerate instead of open */ }\n} else {\n  FSDataInputStream in = fs.open(p);\n}","typeGuard":"static boolean isOpenableFile(FileStatus st) {\n  return st.isFile();\n}","tryCatchPattern":"try {\n  return fs.open(p);\n} catch (FileNotFoundException e) {\n  if (e.getMessage() != null && e.getMessage().endsWith('is a directory')) {\n    // caller passed a directory: fall back to listing\n    return null; // or throw a clearer domain error\n  }\n  throw e;\n}","preventionTips":["Always branch on FileStatus.isFile() before open","Glob results include directories: filter them","Cat/read utilities should check the status type first"],"tags":["cosn","hadoop","open","is-a-directory","file-not-found"],"backgroundTag":"open-on-directory","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}