apache/hadoop · error · IOException

policyName == null

Error message

policyName == null

What it means

Null guard in WebHdfsFileSystem.setStoragePolicy: policyName must not be null, otherwise IOException('policyName == null') is thrown before the SETSTORAGEPOLICY request. The guard exists because the value flows into a StoragePolicyParam used to build the URL and would otherwise fail later with a less clear error.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java:2151

      for (InetSocketAddress addr : addrs.values()) {
        ret.add(addr);
      }
    }

    InetSocketAddress[] r = new InetSocketAddress[ret.size()];
    return ret.toArray(r);
  }

  @Override
  public String getCanonicalServiceName() {
    return tokenServiceName == null ? super.getCanonicalServiceName()
        : tokenServiceName.toString();
  }

  @Override
  public void setStoragePolicy(Path p, String policyName) throws IOException {
    if (policyName == null) {
      throw new IOException("policyName == null");
    }
    statistics.incrementWriteOps(1);
    storageStatistics.incrementOpCounter(OpType.SET_STORAGE_POLICY);
    final HttpOpParam.Op op = PutOpParam.Op.SETSTORAGEPOLICY;
    new FsPathRunner(op, p, new StoragePolicyParam(policyName)).run();
  }

  @Override
  public Collection<BlockStoragePolicy> getAllStoragePolicies()
      throws IOException {
    statistics.incrementReadOps(1);
    storageStatistics.incrementOpCounter(OpType.GET_STORAGE_POLICIES);
    final HttpOpParam.Op op = GetOpParam.Op.GETALLSTORAGEPOLICY;
    return new FsPathResponseRunner<Collection<BlockStoragePolicy>>(op, null) {
      @Override
      Collection<BlockStoragePolicy> decodeResponse(Map<?, ?> json)
          throws IOException {
        return JsonUtilClient.getStoragePolicies(json);

View on GitHub (pinned to 2add963021)

Solutions

  1. Pass a concrete policy name the cluster defines: HOT, WARM, COLD, ALL_SSD, ONE_SSD, LAZY_PERSIST, PROVIDED (subject to cluster config)
  2. If the name comes from configuration, default it explicitly, e.g. conf.get("my.storage.policy", "HOT")
  3. Discover valid names at runtime via fs.getAllStoragePolicies() (or hdfs storagepolicies -listPolicies) and validate before calling
  4. To remove a policy use fs.unsetStoragePolicy(path) (UNSETSTORAGEPOLICY op) instead of passing null

Example fix

// before
String policy = conf.get("my.storage.policy"); // null if key unset
fs.setStoragePolicy(path, policy);
// after
String policy = conf.get("my.storage.policy", "HOT");
fs.setStoragePolicy(path, policy);
Defensive patterns

Strategy: validation

Validate before calling

String policy = Objects.requireNonNull(policyName,
    "storage policy name required (e.g. HOT, WARM, COLD, ALL_SSD, ONE_SSD)");
// optionally verify against the cluster's actual policies:
boolean known = StreamSupport.stream(fs.getAllStoragePolicies().spliterator(), false)
    .anyMatch(p -> p.getName().equals(policy));
if (!known) throw new IllegalArgumentException("Unknown policy: " + policy);

Prevention

When it happens

Trigger: Calling fs.setStoragePolicy(path, null), typically from code that reads the policy name from configuration, a DB field, or user input that was never populated.

Common situations: Policy name sourced from a config key that is missing; CLI/REST frontends forwarding an optional --policy argument that was omitted; porting code from DistributedFileSystem which carries an equivalent guard.

Related errors


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