{"record":{"id":"5a64827b04bb7007","repo":"apache/hadoop","slug":"file-directory-does-not-exist-iip-getpath","errorCode":null,"errorMessage":"\"File/Directory does not exist: \" + iip.getPath()","messagePattern":"\"File/Directory does not exist: \" \\+ iip\\.getPath\\(\\)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java","lineNumber":213,"sourceCode":"    return fsd.getAuditFileInfo(iip);\n  }\n\n  static BlockStoragePolicy[] getStoragePolicies(BlockManager bm)\n      throws IOException {\n    return bm.getStoragePolicies();\n  }\n\n  static BlockStoragePolicy getStoragePolicy(FSDirectory fsd,\n      FSPermissionChecker pc, BlockManager bm, String path) throws IOException {\n    fsd.readLock();\n    try {\n      final INodesInPath iip = fsd.resolvePath(pc, path, DirOp.READ_LINK);\n      if (fsd.isPermissionEnabled()) {\n        fsd.checkPathAccess(pc, iip, FsAction.READ);\n      }\n      INode inode = iip.getLastINode();\n      if (inode == null) {\n        throw new FileNotFoundException(\"File/Directory does not exist: \"\n            + iip.getPath());\n      }\n      return bm.getStoragePolicy(inode.getStoragePolicyID());\n    } finally {\n      fsd.readUnlock();\n    }\n  }\n\n  static long getPreferredBlockSize(FSDirectory fsd, FSPermissionChecker pc,\n      String src) throws IOException {\n    fsd.readLock();\n    try {\n      final INodesInPath iip = fsd.resolvePath(pc, src, DirOp.READ_LINK);\n      return INodeFile.valueOf(iip.getLastINode(), iip.getPath())\n          .getPreferredBlockSize();\n    } finally {\n      fsd.readUnlock();\n    }","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java#L195-L231","documentation":"getStoragePolicy resolves the path (DirOp.READ_LINK), checks READ permission, then requires a non-null last INode; nothing at the path throws FileNotFoundException with the resolved path. This is the standard missing-path guard for the storage-policy query used by 'hdfs storagepolicies -getStoragePolicy'.","triggerScenarios":"DistributedFileSystem.getStoragePolicy(path) on a path that does not exist: deleted between listing and lookup, typo, wrong partition/mount path, or a manifest entry that was never created.","commonSituations":"Policy audit scripts iterating stale inventories; files deleted by retention jobs mid-audit; path construction bugs in generated manifests.","solutions":["Guard with fs.exists(path) and accept it is racy - still handle FileNotFoundException in the call.","For audit/reporting tools, catch FileNotFoundException per path and report/skip rather than abort the run.","Fix the manifest or upstream job if the entries were expected to exist."],"exampleFix":"// before\nBlockStoragePolicy p = ((DistributedFileSystem) fs).getStoragePolicy(path);\n\n// after\nif (!fs.exists(path)) {\n  LOG.warn(\"skip policy check, path missing: {}\", path);\n  return;\n}\nBlockStoragePolicy p = ((DistributedFileSystem) fs).getStoragePolicy(path);","handlingStrategy":"validation","validationCode":"if (!fs.exists(path)) {\n  LOG.warn(\"cannot query storage policy, path missing: {}\", path);\n  return null;\n}\nreturn ((DistributedFileSystem) fs).getStoragePolicy(path);","typeGuard":null,"tryCatchPattern":"try {\n  return dfs.getStoragePolicy(path);\n} catch (FileNotFoundException e) {\n  return null; // audit tools: record and continue with the next path\n}","preventionTips":["Skip-or-report per path in batch audit tools rather than failing the run.","Regenerate manifests from live listings instead of stale snapshots."],"tags":["hdfs","storage-policy","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}