{"record":{"id":"9dd5f2f5a937a391","repo":"apache/hadoop","slug":"policyname-null","errorCode":null,"errorMessage":"policyName == null","messagePattern":"policyName == null","errorType":"validation","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java","lineNumber":2151,"sourceCode":"      for (InetSocketAddress addr : addrs.values()) {\n        ret.add(addr);\n      }\n    }\n\n    InetSocketAddress[] r = new InetSocketAddress[ret.size()];\n    return ret.toArray(r);\n  }\n\n  @Override\n  public String getCanonicalServiceName() {\n    return tokenServiceName == null ? super.getCanonicalServiceName()\n        : tokenServiceName.toString();\n  }\n\n  @Override\n  public void setStoragePolicy(Path p, String policyName) throws IOException {\n    if (policyName == null) {\n      throw new IOException(\"policyName == null\");\n    }\n    statistics.incrementWriteOps(1);\n    storageStatistics.incrementOpCounter(OpType.SET_STORAGE_POLICY);\n    final HttpOpParam.Op op = PutOpParam.Op.SETSTORAGEPOLICY;\n    new FsPathRunner(op, p, new StoragePolicyParam(policyName)).run();\n  }\n\n  @Override\n  public Collection<BlockStoragePolicy> getAllStoragePolicies()\n      throws IOException {\n    statistics.incrementReadOps(1);\n    storageStatistics.incrementOpCounter(OpType.GET_STORAGE_POLICIES);\n    final HttpOpParam.Op op = GetOpParam.Op.GETALLSTORAGEPOLICY;\n    return new FsPathResponseRunner<Collection<BlockStoragePolicy>>(op, null) {\n      @Override\n      Collection<BlockStoragePolicy> decodeResponse(Map<?, ?> json)\n          throws IOException {\n        return JsonUtilClient.getStoragePolicies(json);","sourceCodeStart":2133,"sourceCodeEnd":2169,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java#L2133-L2169","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a concrete policy name the cluster defines: HOT, WARM, COLD, ALL_SSD, ONE_SSD, LAZY_PERSIST, PROVIDED (subject to cluster config)","If the name comes from configuration, default it explicitly, e.g. conf.get(\"my.storage.policy\", \"HOT\")","Discover valid names at runtime via fs.getAllStoragePolicies() (or hdfs storagepolicies -listPolicies) and validate before calling","To remove a policy use fs.unsetStoragePolicy(path) (UNSETSTORAGEPOLICY op) instead of passing null"],"exampleFix":"// before\nString policy = conf.get(\"my.storage.policy\"); // null if key unset\nfs.setStoragePolicy(path, policy);\n// after\nString policy = conf.get(\"my.storage.policy\", \"HOT\");\nfs.setStoragePolicy(path, policy);","handlingStrategy":"validation","validationCode":"String policy = Objects.requireNonNull(policyName,\n    \"storage policy name required (e.g. HOT, WARM, COLD, ALL_SSD, ONE_SSD)\");\n// optionally verify against the cluster's actual policies:\nboolean known = StreamSupport.stream(fs.getAllStoragePolicies().spliterator(), false)\n    .anyMatch(p -> p.getName().equals(policy));\nif (!known) throw new IllegalArgumentException(\"Unknown policy: \" + policy);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["List valid names once via fs.getAllStoragePolicies() (or hdfs storagepolicies -listPolicies) and cache them","Default optional policy inputs to 'HOT' or reject early in your CLI layer","Unset policies through unsetStoragePolicy()/UNSETSTORAGEPOLICY, not null"],"tags":["webhdfs","null-argument","storage-policy"],"backgroundTag":"null-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}