{"record":{"id":"e7e21c517f5d9b0c","repo":"apache/hadoop","slug":"iip-getpath-is-not-a-file-or-directory","errorCode":null,"errorMessage":"iip.getPath() + \" is not a file or directory\"","messagePattern":"iip\\.getPath\\(\\) \\+ \" is not a file or directory\"","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":468,"sourceCode":"              + \" cannot be set after file creation.\");\n        }\n      }\n\n      BlockStoragePolicy currentPolicy =\n          bm.getStoragePolicy(inode.getLocalStoragePolicyID());\n\n      if (currentPolicy != null && currentPolicy.isCopyOnCreateFile()) {\n        throw new HadoopIllegalArgumentException(\n            \"Existing policy \" + currentPolicy.getName() +\n                \" cannot be changed after file creation.\");\n      }\n      inode.asFile().setStoragePolicyID(policyId, snapshotId);\n    } else if (inode.isDirectory()) {\n      FSDirectory.LOG.debug(\"DIR* FSDirAAr.unprotectedSetStoragePolicy for \" +\n              \"Directory.\");\n      setDirStoragePolicy(fsd, iip, policyId);\n    } else {\n      throw new FileNotFoundException(iip.getPath()\n          + \" is not a file or directory\");\n    }\n  }\n\n  private static void setDirStoragePolicy(\n      FSDirectory fsd, INodesInPath iip, byte policyId) throws IOException {\n    INode inode = FSDirectory.resolveLastINode(iip);\n    List<XAttr> existingXAttrs = XAttrStorage.readINodeXAttrs(inode);\n    XAttr xAttr = BlockStoragePolicySuite.buildXAttr(policyId);\n    List<XAttr> newXAttrs = null;\n    if (policyId == HdfsConstants.BLOCK_STORAGE_POLICY_ID_UNSPECIFIED) {\n      List<XAttr> toRemove = Lists.newArrayList();\n      toRemove.add(xAttr);\n      List<XAttr> removed = Lists.newArrayList();\n      newXAttrs = FSDirXAttrOp.filterINodeXAttrs(existingXAttrs, toRemove,\n          removed);\n    } else {\n      newXAttrs = FSDirXAttrOp.setINodeXAttrs(fsd, existingXAttrs,","sourceCodeStart":450,"sourceCodeEnd":486,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java#L450-L486","documentation":"unprotectedSetStoragePolicy dispatches on inode type: files get per-file policy handling, directories get recursive/inherited handling, and anything else - which in HDFS means a symlink - throws FileNotFoundException stating the path 'is not a file or directory'. The path exists; it simply cannot carry a storage policy. The FileNotFound type is reused for 'unusable target', which makes it look like a missing-file bug when it is not.","triggerScenarios":"setStoragePolicy / 'hdfs storagepolicies -setStoragePolicy' on an HDFS symlink: the resolved INode is an INodeSymlink, failing both isFile() and isDirectory() - e.g. a 'latest -> 2026-08-22' convenience link inside a managed tree.","commonSituations":"Policy rollouts over trees containing compatibility symlinks; manifests mixing real directories and links; tooling that walks listings without distinguishing link entries.","solutions":["Apply the policy to the symlink's target (resolve the link) or to the parent directory, which real children inherit.","Skip symlinks during bulk operations: check fs.getFileLinkStatus(path).isSymlink() before setting policy.","Avoid placing symlinks in trees you intend to manage with storage policies."],"exampleFix":"// before\nfs.setStoragePolicy(linkPath, \"COLD\"); // FileNotFoundException: not a file or directory\n\n// after: resolve the link, set policy on the real target\nFileStatus st = fs.getFileLinkStatus(linkPath);\nPath target = st.isSymlink() ? st.getSymlink() : linkPath;\nfs.setStoragePolicy(target.makeQualified(fs.getUri(), fs.getWorkingDirectory()), \"COLD\");","handlingStrategy":"type-guard","validationCode":"FileStatus st = fs.getFileLinkStatus(path); // does not follow the link\nif (st.isSymlink()) {\n  throw new IllegalArgumentException(path + \" is a symlink; apply the policy to \"\n      + st.getSymlink() + \" or the parent directory\");\n}","typeGuard":"static Path storagePolicyTarget(FileSystem fs, Path p) throws IOException {\n  FileStatus st = fs.getFileLinkStatus(p); // lstat semantics\n  return st.isSymlink()\n      ? st.getSymlink().makeQualified(fs.getUri(), fs.getWorkingDirectory())\n      : p;\n}","tryCatchPattern":"try {\n  fs.setStoragePolicy(path, policyName);\n} catch (FileNotFoundException e) {\n  if (e.getMessage().endsWith(\"is not a file or directory\")) {\n    // path is a symlink: resolve it and set the policy on the real target\n  }\n}","preventionTips":["Skip symlinks explicitly in bulk policy walks (getFileLinkStatus + isSymlink).","Prefer applying policies to parent directories, which children inherit regardless of type."],"tags":["hdfs","storage-policy","symlink","namenode"],"backgroundTag":"symlink-not-supported","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}