{"record":{"id":"e23abb4b4ba64ff3","repo":"apache/hadoop","slug":"invalid-values-for-quota-namespacequota-and","errorCode":null,"errorMessage":"Invalid values for quota : ${namespaceQuota} and ${storagespaceQuota}","messagePattern":"Invalid values for quota : (.+?) and (.+?)","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":2061,"sourceCode":"\n    final HttpOpParam.Op op = GetOpParam.Op.GETQUOTAUSAGE;\n    return new FsPathResponseRunner<QuotaUsage>(op, p) {\n      @Override\n      QuotaUsage decodeResponse(Map<?, ?> json) {\n        return JsonUtilClient.toQuotaUsage(json);\n      }\n    }.run();\n  }\n\n  @Override\n  public void setQuota(Path p, final long namespaceQuota,\n      final long storagespaceQuota) throws IOException {\n    // sanity check\n    if ((namespaceQuota <= 0 &&\n        namespaceQuota != HdfsConstants.QUOTA_RESET) ||\n        (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) {","sourceCodeStart":2043,"sourceCodeEnd":2079,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java#L2043-L2079","documentation":"Client-side fast-fail sanity check in WebHdfsFileSystem.setQuota before sending the SETQUOTA REST request: the namespace quota must be positive or HdfsConstants.QUOTA_RESET (-1), and the storage-space quota must be non-negative or QUOTA_RESET. An IllegalArgumentException is thrown locally rather than bothering the NameNode with an invalid request. Zero is not a legal quota for either dimension in this check.","triggerScenarios":"Calling fs.setQuota(path, ns, ss) with namespaceQuota <= 0 (other than -1) or storagespaceQuota < 0 (other than -1), e.g. setQuota(p, 0, 1073741824) or setQuota(p, -5, -5).","commonSituations":"Passing 0 intending 'no quota' (use QUOTA_RESET to clear or QUOTA_DONT_SET to leave unchanged); arithmetic that underflows into negatives; porting CLI 'dfsadmin -setQuota -1' semantics but writing 0; code paths that default unset longs to 0.","solutions":["Pass a positive namespace quota and a non-negative storage quota","To clear a quota pass HdfsConstants.QUOTA_RESET (-1) for that dimension; to leave it unchanged pass HdfsConstants.QUOTA_DONT_SET (Long.MAX_VALUE), which also passes this check","Validate values at the call site before invoking setQuota (mirror the check below) so callers get your own error message"],"exampleFix":"// before\nfs.setQuota(path, 0, 1024L * 1024 * 1024); // 0 is invalid here\n// after: clear the namespace quota, set a 1 GB space quota\nfs.setQuota(path, HdfsConstants.QUOTA_RESET, 1024L * 1024 * 1024);","handlingStrategy":"validation","validationCode":"static void checkQuotaArgs(long nsQuota, long ssQuota) {\n  if ((nsQuota <= 0 && nsQuota != HdfsConstants.QUOTA_RESET)\n      || (ssQuota < 0 && ssQuota != HdfsConstants.QUOTA_RESET)) {\n    throw new IllegalArgumentException(\"ns=\" + nsQuota + \", ss=\" + ssQuota\n        + \": use positive quotas, HdfsConstants.QUOTA_RESET to clear,\");\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  fs.setQuota(p, ns, ss);\n} catch (IllegalArgumentException e) {\n  // client-side reject: fix the numbers, do not retry\n  throw new ConfigurationException(\"Bad quota values: \" + e.getMessage(), e);\n}","preventionTips":["Never use 0 to mean 'no quota' — use QUOTA_RESET (-1) to clear, QUOTA_DONT_SET to skip","Validate quota inputs at your own boundary so users see your messages","Property-load quotas from config as strings and parse with a whitelist (-1 or positive long)"],"tags":["webhdfs","quota","argument-validation","hdfs"],"backgroundTag":"invalid-quota-value","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}