{"record":{"id":"ea40662b8457e5cf","repo":"apache/hadoop","slug":"doesn-t-support-getstoragepolicy","errorCode":null,"errorMessage":"{} doesn't support getStoragePolicy","messagePattern":"(.+?) doesn't support getStoragePolicy","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java","lineNumber":1560,"sourceCode":"   * Unset the storage policy set for a given file or directory.\n   * @param src file or directory path.\n   * @throws IOException raised on errors performing I/O.\n   */\n  public void unsetStoragePolicy(final Path src) throws IOException {\n    throw new UnsupportedOperationException(getClass().getSimpleName()\n        + \" doesn't support unsetStoragePolicy\");\n  }\n\n  /**\n   * Retrieve the storage policy for a given file or directory.\n   *\n   * @param src file or directory path.\n   * @return storage policy for give file.\n   * @throws IOException raised on errors performing I/O.\n   */\n  public BlockStoragePolicySpi getStoragePolicy(final Path src)\n      throws IOException {\n    throw new UnsupportedOperationException(getClass().getSimpleName()\n        + \" doesn't support getStoragePolicy\");\n  }\n\n  /**\n   * Retrieve all the storage policies supported by this file system.\n   *\n   * @return all storage policies supported by this filesystem.\n   * @throws IOException raised on errors performing I/O.\n   */\n  public Collection<? extends BlockStoragePolicySpi> getAllStoragePolicies()\n      throws IOException {\n    throw new UnsupportedOperationException(getClass().getSimpleName()\n        + \" doesn't support getAllStoragePolicies\");\n  }\n\n  @Override //Object\n  public int hashCode() {\n    return myUri.hashCode();","sourceCodeStart":1542,"sourceCodeEnd":1578,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java#L1542-L1578","documentation":"AbstractFileSystem.getStoragePolicy(Path) is a default stub that throws UnsupportedOperationException with the implementing class name. Querying the effective block storage policy is only implemented by HDFS-backed filesystems; the stub fires for every other scheme reached through FileContext.","triggerScenarios":"FileContext.getStoragePolicy(src) on file:// or object-store paths; audit/reporting tools that print each path's policy; `hdfs fsck -storagepolicies`-style logic driven through the generic API against a non-HDFS mount.","commonSituations":"Compliance/audit jobs enumerate policies across mixed-scheme datasets and hit the stub on the first non-HDFS path; the same jar reused in local dev where defaultFS is file://.","solutions":["Query storage policies only for hdfs:// paths.","Use DistributedFileSystem.getStoragePolicy for the supported flow.","Feature-detect per filesystem instance once, cache the result, and skip policy reporting where unsupported.","Catch UnsupportedOperationException and report \"n/a\" instead of failing the whole audit."],"exampleFix":"// before\nBlockStoragePolicySpi p = fc.getStoragePolicy(path); // throws on file://\n\n// after\nBlockStoragePolicySpi p = null;\ntry {\n  p = fc.getStoragePolicy(path);\n} catch (UnsupportedOperationException e) {\n  p = null; // no policy engine on this filesystem\n}","handlingStrategy":"try-catch","validationCode":"static boolean policyOpsSupported(Path p) {\n  return \"hdfs\".equals(p.toUri().getScheme());\n}","typeGuard":null,"tryCatchPattern":"BlockStoragePolicySpi policy = null;\ntry {\n  policy = fc.getStoragePolicy(path);\n} catch (UnsupportedOperationException e) {\n  policy = null; // report as n/a\n}","preventionTips":["Cache a per-filesystem 'policies available' flag from one probe call","Let audit tools report n/a instead of aborting on the first non-HDFS path"],"tags":["hadoop","filesystem","storage-policy","hdfs","unsupportedoperationexception"],"backgroundTag":"storage-policy-unsupported","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}