{"record":{"id":"0debcb5507b5f73e","repo":"apache/hadoop","slug":"no-such-file-or-directory-0debcb","errorCode":null,"errorMessage":"No such file or directory '{}'","messagePattern":"No such file or 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":393,"sourceCode":"\n    if (!key.endsWith(PATH_DELIMITER)) {\n      key += PATH_DELIMITER;\n    }\n\n    // Considering that the object store's directory is a common prefix in\n    // the object key, it needs to check the existence of the path by listing\n    // the COS key.\n    LOG.debug(\"List COS key: [{}] to check the existence of the path.\", key);\n    PartialListing listing = store.list(key, 1);\n    if (listing.getFiles().length > 0\n        || listing.getCommonPrefixes().length > 0) {\n      if (LOG.isDebugEnabled()) {\n        LOG.debug(\"Path: [{}] is a directory. COS key: [{}]\", f, key);\n      }\n      return newDirectory(absolutePath);\n    }\n\n    throw new FileNotFoundException(\n        \"No such file or directory '\" + absolutePath + \"'\");\n  }\n\n  @Override\n  public URI getUri() {\n    return uri;\n  }\n\n  /**\n   * <p>\n   * If <code>f</code> is a file, this method will make a single call to COS.\n   * If <code>f</code> is a directory,\n   * this method will make a maximum of ( <i>n</i> / 199) + 2 calls to cos,\n   * where <i>n</i> is the total number of files\n   * and directories contained directly in <code>f</code>.\n   * </p>\n   */\n  @Override","sourceCodeStart":375,"sourceCodeEnd":411,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-cos/src/main/java/org/apache/hadoop/fs/cosn/CosNFileSystem.java#L375-L411","documentation":"CosNFileSystem.getFileStatus throws FileNotFoundException('No such file or directory <path>') when neither an object at the exact key nor any listing entry under the key exists. CosN probes the object key and then lists one entry to detect an implicit directory; both empty means the path does not exist in the bucket. Because open, delete, rename source checks, mkdirs and create all route through getFileStatus, this error surfaces from many call sites.","triggerScenarios":"fs.open / fs.delete / fs.getFileStatus / rename with a missing source path; reading output of a job that never wrote it; wrong bucket or wrong fs.defaultFS so lookups hit a different bucket; path built with wrong prefix or separator; COS visibility lag right after an external writer uploaded the object.","commonSituations":"Misconfigured fs.cosn.<bucket>.bucket or credentials pointing at the wrong bucket; consuming a path before the producer committed; typo'd or case-mismatched path; assuming a directory exists when only implicit (marker-less) directories do.","solutions":["Verify with fs.exists(p) and fix the path spelling/prefix, or wait for the producer to commit.","Print fs.getUri() and the bucket configuration once at startup to confirm you are querying the bucket you expect.","If racing a producer, poll fs.exists(p) with bounded backoff instead of failing immediately.","List the parent directory (fs.listStatus(parent)) to see what is actually stored at that level."],"exampleFix":"// before\nFSDataInputStream in = fs.open(new Path('cosn://bkt/out/part-00000')); // FileNotFoundException\n\n// after\nPath p = new Path('cosn://bkt/out/part-00000');\nif (!fs.exists(p)) {\n  throw new NoSuchElementException('Input not produced: ' + p);\n}\nFSDataInputStream in = fs.open(p);","handlingStrategy":"try-catch","validationCode":"// Cheap pre-check; note exists() and open() still race, so pair with try-catch\nif (!fs.exists(p)) {\n  // handle missing input before calling open/delete/rename\n}","typeGuard":"static boolean isMissingPath(Throwable t) {\n  return t instanceof FileNotFoundException;\n}","tryCatchPattern":"try {\n  return fs.open(p);\n} catch (FileNotFoundException e) {\n  if (awaitProducer && pollExists(fs, p, 30)) { return fs.open(p); }\n  throw new NoSuchElementException('Input not produced: ' + p);\n}","preventionTips":["Validate inputs against the producing job's commit, not assumptions","Log fs.getUri() at startup to catch wrong-bucket configuration","Remember exists() then open() is a race; only try-catch makes it atomic"],"tags":["cosn","hadoop","file-not-found","getfilestatus","object-store"],"backgroundTag":"file-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}