{"record":{"id":"a2b2eec900f0382c","repo":"apache/hadoop","slug":"invalid-storage-type-null-a2b2ee","errorCode":null,"errorMessage":"Invalid storage type (null)","messagePattern":"Invalid storage type \\(null\\)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java","lineNumber":2080,"sourceCode":"          namespaceQuota + \" and \" + storagespaceQuota);\n    }\n\n    statistics.incrementWriteOps(1);\n    storageStatistics.incrementOpCounter(OpType.SET_QUOTA_USAGE);\n\n    final HttpOpParam.Op op = PutOpParam.Op.SETQUOTA;\n    new FsPathRunner(op, p, new NameSpaceQuotaParam(namespaceQuota),\n        new StorageSpaceQuotaParam(storagespaceQuota)).run();\n  }\n\n  @Override\n  public void setQuotaByStorageType(Path path, StorageType type, long quota)\n      throws IOException {\n    if (quota <= 0 && quota != HdfsConstants.QUOTA_RESET) {\n      throw new IllegalArgumentException(\"Invalid values for quota :\" + quota);\n    }\n    if (type == null) {\n      throw new IllegalArgumentException(\"Invalid storage type (null)\");\n    }\n    if (!type.supportTypeQuota()) {\n      throw new IllegalArgumentException(\n          \"Quota for storage type '\" + type.toString() + \"' is not supported\");\n    }\n\n    statistics.incrementWriteOps(1);\n    storageStatistics.incrementOpCounter(OpType.SET_QUOTA_BYTSTORAGEYPE);\n\n    final HttpOpParam.Op op = PutOpParam.Op.SETQUOTABYSTORAGETYPE;\n    new FsPathRunner(op, path, new StorageTypeParam(type.name()),\n        new StorageSpaceQuotaParam(quota)).run();\n  }\n\n  @Override\n  public MD5MD5CRC32FileChecksum getFileChecksum(final Path p\n  ) throws IOException {\n    statistics.incrementReadOps(1);","sourceCodeStart":2062,"sourceCodeEnd":2098,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java#L2062-L2098","documentation":"Null guard in WebHdfsFileSystem.setQuotaByStorageType: the StorageType argument must not be null, otherwise IllegalArgumentException('Invalid storage type (null)') is thrown before any request is issued. It protects later code (type.name(), type.supportTypeQuota()) from an NPE and gives a clearer message.","triggerScenarios":"Calling fs.setQuotaByStorageType(path, null, quota), typically because a type variable came from configuration parsing or a map lookup that returned null.","commonSituations":"StorageType parsed from a config key that is absent (custom parse returning null instead of throwing); Map<String,StorageType> miss; optional parameters wired straight through from CLI/JSON into the API.","solutions":["Resolve the StorageType before the call and fail with a clear message if it cannot be parsed (StorageType.valueOf throws on unknown names; handle that too)","Default to a sensible type (commonly StorageType.DISK) when configuration omits it","Add an Objects.requireNonNull(type, \"storage type\") at your own API boundary"],"exampleFix":"// before\nStorageType t = parseType(conf.get(\"my.quota.type\")); // may return null\nfs.setQuotaByStorageType(path, t, quota);\n// after\nStorageType t = Optional.ofNullable(parseType(conf.get(\"my.quota.type\")))\n    .orElseThrow(() -> new IllegalArgumentException(\"my.quota.type missing/unknown\"));\nfs.setQuotaByStorageType(path, t, quota);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(type, \"storage type must not be null\");\nStorageType t = StorageType.valueOf(\n    Objects.requireNonNull(rawTypeName, \"storage type config missing\")\n        .trim().toUpperCase(Locale.ROOT));\nfs.setQuotaByStorageType(path, t, quota);","typeGuard":"static boolean isUsableStorageType(StorageType t) {\n  return t != null;\n}","tryCatchPattern":null,"preventionTips":["Parse storage types from config eagerly at startup so bad/missing values fail then, not mid-quota-call","Require the storage-type config key in your tooling's schema instead of making it optional"],"tags":["webhdfs","null-argument","storage-type","quota"],"backgroundTag":"null-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}