{"record":{"id":"230ef959752549e1","repo":"apache/hadoop","slug":"doesn-t-support-getallstoragepolicies","errorCode":null,"errorMessage":"{} doesn't support getAllStoragePolicies","messagePattern":"(.+?) doesn't support getAllStoragePolicies","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java","lineNumber":1572,"sourceCode":"   * @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();\n  }\n  \n  @Override //Object\n  public boolean equals(Object other) {\n    if (!(other instanceof AbstractFileSystem)) {\n      return false;\n    }\n    return myUri.equals(((AbstractFileSystem) other).myUri);\n  }\n\n  /**\n   * Open a file with the given set of options.","sourceCodeStart":1554,"sourceCodeEnd":1590,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java#L1554-L1590","documentation":"AbstractFileSystem.getAllStoragePolicies() is a default stub that throws UnsupportedOperationException naming the subclass. Enumerating the storage-policy catalog is HDFS-only; through FileContext any other resolved implementation fails with this error before returning a collection.","triggerScenarios":"FileContext.getAllStoragePolicies() on local or object-store filesystems; tools that populate a policy dropdown/list from the filesystem (like `hdfs dfsadmin -listStoragePolicies` but via the generic API) pointed at a non-HDFS defaultFS.","commonSituations":"Cluster-management or UI code enumerating policies on connect, executed in tests with file://; a client configured for the wrong endpoint (s3a endpoint URL) where the code assumed HDFS.","solutions":["Call getAllStoragePolicies only on hdfs:// filesystems.","Use DistributedFileSystem.getAllStoragePolicies or `hdfs dfsadmin -listStoragePolicies`.","Probe once at startup, catch UnsupportedOperationException, and cache \"policies unavailable\" for that filesystem.","Default to an empty policy list in UIs when the backend has no policy engine."],"exampleFix":"// before\nCollection<? extends BlockStoragePolicySpi> ps = fc.getAllStoragePolicies();\n\n// after\nCollection<? extends BlockStoragePolicySpi> ps;\ntry {\n  ps = fc.getAllStoragePolicies();\n} catch (UnsupportedOperationException e) {\n  ps = Collections.emptyList();\n}","handlingStrategy":"try-catch","validationCode":"static boolean policyOpsSupported(Path p) {\n  return \"hdfs\".equals(p.toUri().getScheme());\n}","typeGuard":null,"tryCatchPattern":"try {\n  policies = fc.getAllStoragePolicies();\n} catch (UnsupportedOperationException e) {\n  policies = Collections.emptyList();\n}","preventionTips":["Enumerate policies once per filesystem connection, not per path","Default UIs/config tools to an empty policy list when the probe throws"],"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"}