{"record":{"id":"02c1fb1e589ca651","repo":"apache/hadoop","slug":"invalid-values-for-quota-quota","errorCode":null,"errorMessage":"Invalid values for quota :${quota}","messagePattern":"Invalid values for quota :(.+?)","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":2077,"sourceCode":"        (storagespaceQuota < 0 &&\n            storagespaceQuota != HdfsConstants.QUOTA_RESET)) {\n      throw new IllegalArgumentException(\"Invalid values for quota : \" +\n          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","sourceCodeStart":2059,"sourceCodeEnd":2095,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java#L2059-L2095","documentation":"Fast-fail check in WebHdfsFileSystem.setQuotaByStorageType: a per-storage-type quota must be positive or equal to HdfsConstants.QUOTA_RESET (-1); anything else (0, negative values other than -1) throws IllegalArgumentException before the SETQUOTABYSTORAGETYPE request is sent. It mirrors the NameNode's own quota validation on the client side.","triggerScenarios":"Calling fs.setQuotaByStorageType(path, type, quota) with quota == 0 or quota < 0 && quota != -1, e.g. setQuotaByStorageType(p, StorageType.SSD, 0).","commonSituations":"Using 0 to mean 'remove the type quota' instead of QUOTA_RESET; uninitialized long fields defaulting to 0; porting scripts that pass -1 for 'unlimited' but a -2 or 0 slips through from arithmetic.","solutions":["Pass a positive quota value for the storage type","To remove the type quota pass HdfsConstants.QUOTA_RESET (-1)","Validate quota > 0 || quota == HdfsConstants.QUOTA_RESET at the call site before the API call"],"exampleFix":"// before\nfs.setQuotaByStorageType(path, StorageType.SSD, 0);\n// after: clear the SSD quota\nfs.setQuotaByStorageType(path, StorageType.SSD, HdfsConstants.QUOTA_RESET);","handlingStrategy":"validation","validationCode":"static boolean isValidTypeQuota(long quota) {\n  return quota > 0 || quota == HdfsConstants.QUOTA_RESET;\n}\n\nif (!isValidTypeQuota(quota)) {\n  throw new IllegalArgumentException(\"quota must be > 0 or QUOTA_RESET(-1), got \" + quota);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat -1 as the only legal non-positive quota value","Default unset numeric config to QUOTA_RESET explicitly, never 0","Unit-test quota plumbing with -1, 0, 1, Long.MAX_VALUE"],"tags":["webhdfs","quota","storage-type","argument-validation"],"backgroundTag":"invalid-quota-value","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}