{"record":{"id":"bb193d662a6ee3d5","repo":"apache/hadoop","slug":"doesn-t-support-unsetstoragepolicy","errorCode":null,"errorMessage":"{} doesn't support unsetStoragePolicy","messagePattern":"(.+?) doesn't support unsetStoragePolicy","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java","lineNumber":1547,"sourceCode":"   * @param policyName the name of the target storage policy. The list\n   *                   of supported Storage policies can be retrieved\n   *                   via {@link #getAllStoragePolicies}.\n   * @throws IOException raised on errors performing I/O.\n   */\n  public void setStoragePolicy(final Path path, final String policyName)\n      throws IOException {\n    throw new UnsupportedOperationException(getClass().getSimpleName()\n        + \" doesn't support setStoragePolicy\");\n  }\n\n\n  /**\n   * 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.","sourceCodeStart":1529,"sourceCodeEnd":1565,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java#L1529-L1565","documentation":"AbstractFileSystem.unsetStoragePolicy(Path) is a default stub that throws UnsupportedOperationException naming the subclass. Unsetting (reverting to inherited/default policy) is HDFS-only; filesystems without a storage-policy engine keep the stub. The error indicates scheme-level non-support, not a missing or already-unset policy.","triggerScenarios":"FileContext.unsetStoragePolicy(src) against non-HDFS schemes; policy-management code that unsets policies during directory reorganization run on local or object-store paths.","commonSituations":"Policy lifecycle scripts (set on ingest, unset on archive) run against the wrong cluster/endpoint; test environments with file:// defaultFS; viewfs mounts to non-HDFS targets.","solutions":["Restrict unsetStoragePolicy calls to hdfs:// paths.","Use DistributedFileSystem.unsetStoragePolicy / `hdfs dfsadmin -unsetStoragePolicy` for the supported path.","Gate by URI scheme in shared code.","Catch UnsupportedOperationException and skip when the store has no policy concept."],"exampleFix":"// before\nfc.unsetStoragePolicy(path); // throws on unsupported scheme\n\n// after\nif (\"hdfs\".equals(path.toUri().getScheme())) {\n  fc.unsetStoragePolicy(path);\n}","handlingStrategy":"validation","validationCode":"static boolean policyOpsSupported(Path p) {\n  return \"hdfs\".equals(p.toUri().getScheme());\n}","typeGuard":null,"tryCatchPattern":"try {\n  fc.unsetStoragePolicy(path);\n} catch (UnsupportedOperationException e) {\n  // nothing to unset: store has no policies\n}","preventionTips":["Only unset policies on paths where a set previously succeeded","Track policy state per scheme in your management tooling"],"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"}