{"record":{"id":"a1d335c5e66bda1e","repo":"apache/hadoop","slug":"invalid-values-for-quota-and","errorCode":null,"errorMessage":"Invalid values for quota : {} and {}","messagePattern":"Invalid values for quota : (.+?) and (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java","lineNumber":2647,"sourceCode":"      }\n    }\n  }\n\n  /**\n   * Sets or resets quotas for a directory.\n   * @see ClientProtocol#setQuota(String, long, long, StorageType)\n   */\n  void setQuota(String src, long namespaceQuota, long storagespaceQuota)\n      throws IOException {\n    checkOpen();\n    // sanity check\n    if ((namespaceQuota <= 0 &&\n          namespaceQuota != HdfsConstants.QUOTA_DONT_SET &&\n          namespaceQuota != HdfsConstants.QUOTA_RESET) ||\n        (storagespaceQuota < 0 &&\n            storagespaceQuota != HdfsConstants.QUOTA_DONT_SET &&\n            storagespaceQuota != HdfsConstants.QUOTA_RESET)) {\n      throw new IllegalArgumentException(\"Invalid values for quota : \" +\n          namespaceQuota + \" and \" +\n          storagespaceQuota);\n\n    }\n    try (TraceScope ignored = newPathTraceScope(\"setQuota\", src)) {\n      // Pass null as storage type for traditional namespace/storagespace quota.\n      namenode.setQuota(src, namespaceQuota, storagespaceQuota, null);\n    } catch (RemoteException re) {\n      throw re.unwrapRemoteException(AccessControlException.class,\n          FileNotFoundException.class,\n          NSQuotaExceededException.class,\n          DSQuotaExceededException.class,\n          QuotaByStorageTypeExceededException.class,\n          UnresolvedPathException.class,\n          SnapshotAccessControlException.class);\n    }\n  }\n","sourceCodeStart":2629,"sourceCodeEnd":2665,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java#L2629-L2665","documentation":"DFSClient.setQuota validates before the RPC: the namespace quota must be positive or one of the sentinels HdfsConstants.QUOTA_DONT_SET (Long.MAX_VALUE, leave unchanged) / QUOTA_RESET (-1, clear), and the storage-space quota must be non-negative or the same sentinels. Anything else — notably 0 for namespace (not a sentinel here) or negatives other than -1 — throws IllegalArgumentException.","triggerScenarios":"Calling setQuota with values like -5, Long.MIN_VALUE sentinel mistakes, or 0 used for namespace 'unlimited'; wrappers mapping user strings ('none', 'inherit', '-1') to longs incorrectly; arithmetic that computes quota deltas underflowing.","commonSituations":"Quota automation mapping UI/config vocabulary to numeric values; teams assuming 0 means 'no quota' because older CLIs behaved differently in printouts; scripts resetting quotas with the wrong constant.","solutions":["Express intent with the sentinels explicitly: HdfsConstants.QUOTA_DONT_SET to leave a quota unchanged, HdfsConstants.QUOTA_RESET (-1) to clear it, positive values to set it.","Validate at your boundary before calling: namespace must be > 0 or a sentinel; space must be >= 0 or a sentinel.","Check arithmetic that derives quotas (deltas, subtractions) for underflow."],"exampleFix":"// before\nclient.setQuota(dir, nsQuota, spQuota); // nsQuota = 0 or -2 -> IllegalArgumentException\n\n// after\nlong ns = (nsQuota < 0) ? HdfsConstants.QUOTA_RESET : nsQuota; // set: >0, reset: -1\nlong sp = (spQuota < 0) ? HdfsConstants.QUOTA_RESET : spQuota; // >= 0 to set\nclient.setQuota(dir, ns, sp);","handlingStrategy":"validation","validationCode":"boolean okNs = nsQ > 0 || nsQ == HdfsConstants.QUOTA_DONT_SET || nsQ == HdfsConstants.QUOTA_RESET;\nboolean okSp = spQ >= 0 || spQ == HdfsConstants.QUOTA_DONT_SET || spQ == HdfsConstants.QUOTA_RESET;\nif (!(okNs && okSp)) {\n  throw new IllegalArgumentException(\"quota out of range: \" + nsQ + \", \" + spQ);\n}","typeGuard":null,"tryCatchPattern":"catch (IllegalArgumentException e) {\n  // surface the rejected quota pair to the config owner; do not blanket-retry\n}","preventionTips":["Model quota intent as an enum (SET/DONT_SET/RESET) instead of magic longs.","Validate config-parsed quota longs before they reach setQuota.","Remember the sentinels are Long.MAX_VALUE (leave unchanged) and -1 (reset), not 0."],"tags":["hdfs","quota","argument-validation","dfsadmin","configuration"],"backgroundTag":"invalid-quota-value","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}