apache/hadoop · error · UnsupportedOperationException

{} doesn't support getStoragePolicy

Error message

{} doesn't support getStoragePolicy

What it means

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.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java:1560

   * Unset the storage policy set for a given file or directory.
   * @param src file or directory path.
   * @throws IOException raised on errors performing I/O.
   */
  public void unsetStoragePolicy(final Path src) throws IOException {
    throw new UnsupportedOperationException(getClass().getSimpleName()
        + " doesn't support unsetStoragePolicy");
  }

  /**
   * Retrieve the storage policy for a given file or directory.
   *
   * @param src file or directory path.
   * @return storage policy for give file.
   * @throws IOException raised on errors performing I/O.
   */
  public BlockStoragePolicySpi getStoragePolicy(final Path src)
      throws IOException {
    throw new UnsupportedOperationException(getClass().getSimpleName()
        + " doesn't support getStoragePolicy");
  }

  /**
   * Retrieve all the storage policies supported by this file system.
   *
   * @return all storage policies supported by this filesystem.
   * @throws IOException raised on errors performing I/O.
   */
  public Collection<? extends BlockStoragePolicySpi> getAllStoragePolicies()
      throws IOException {
    throw new UnsupportedOperationException(getClass().getSimpleName()
        + " doesn't support getAllStoragePolicies");
  }

  @Override //Object
  public int hashCode() {
    return myUri.hashCode();

View on GitHub (pinned to 2add963021)

Solutions

  1. Query storage policies only for hdfs:// paths.
  2. Use DistributedFileSystem.getStoragePolicy for the supported flow.
  3. Feature-detect per filesystem instance once, cache the result, and skip policy reporting where unsupported.
  4. Catch UnsupportedOperationException and report "n/a" instead of failing the whole audit.

Example fix

// before
BlockStoragePolicySpi p = fc.getStoragePolicy(path); // throws on file://

// after
BlockStoragePolicySpi p = null;
try {
  p = fc.getStoragePolicy(path);
} catch (UnsupportedOperationException e) {
  p = null; // no policy engine on this filesystem
}
Defensive patterns

Strategy: try-catch

Validate before calling

static boolean policyOpsSupported(Path p) {
  return "hdfs".equals(p.toUri().getScheme());
}

Try / catch

BlockStoragePolicySpi policy = null;
try {
  policy = fc.getStoragePolicy(path);
} catch (UnsupportedOperationException e) {
  policy = null; // report as n/a
}

Prevention

When it happens

Trigger: 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.

Common situations: 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://.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/ea40662b8457e5cf. Report an issue: GitHub.