{"record":{"id":"ac2692d028ee581d","repo":"apache/hadoop","slug":"illegal-value-for-nsquota-or-ssquota-nsquot","errorCode":null,"errorMessage":"\"Illegal value for nsQuota or ssQuota : \" + nsQuota + \" and \" + ssQuota","messagePattern":"\"Illegal value for nsQuota or ssQuota : \" \\+ nsQuota \\+ \" and \" \\+ ssQuota","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java","lineNumber":337,"sourceCode":"   * @throws PathIsNotDirectoryException if the path is not a directory.\n   * @throws QuotaExceededException if the directory tree size is\n   *                                greater than the given quota\n   * @throws UnresolvedLinkException if a symlink is encountered in src.\n   * @throws SnapshotAccessControlException if path is in RO snapshot\n   */\n  static INodeDirectory unprotectedSetQuota(\n      FSDirectory fsd, INodesInPath iip, long nsQuota,\n      long ssQuota, StorageType type)\n      throws FileNotFoundException, PathIsNotDirectoryException,\n      QuotaExceededException, UnresolvedLinkException,\n      SnapshotAccessControlException, UnsupportedActionException {\n    assert fsd.hasWriteLock();\n    // sanity check\n    if ((nsQuota < 0 && nsQuota != HdfsConstants.QUOTA_DONT_SET &&\n         nsQuota != HdfsConstants.QUOTA_RESET) ||\n        (ssQuota < 0 && ssQuota != HdfsConstants.QUOTA_DONT_SET &&\n          ssQuota != HdfsConstants.QUOTA_RESET)) {\n      throw new IllegalArgumentException(\"Illegal value for nsQuota or \" +\n                                         \"ssQuota : \" + nsQuota + \" and \" +\n                                         ssQuota);\n    }\n    // sanity check for quota by storage type\n    if ((type != null) && (!fsd.isQuotaByStorageTypeEnabled() ||\n        nsQuota != HdfsConstants.QUOTA_DONT_SET)) {\n      throw new UnsupportedActionException(\n          \"Failed to set quota by storage type because either\" +\n          DFS_QUOTA_BY_STORAGETYPE_ENABLED_KEY + \" is set to \" +\n          fsd.isQuotaByStorageTypeEnabled() + \" or nsQuota value is illegal \" +\n          nsQuota);\n    }\n\n    INodeDirectory dirNode =\n        INodeDirectory.valueOf(iip.getLastINode(), iip.getPath());\n    final QuotaCounts oldQuota = dirNode.getQuotaCounts();\n    final long oldNsQuota = oldQuota.getNameSpace();\n    final long oldSsQuota = oldQuota.getStorageSpace();","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java#L319-L355","documentation":"unprotectedSetQuota sanity-checks the raw longs: any negative nsQuota/ssQuota that is not the -1 QUOTA_RESET sentinel (QUOTA_DONT_SET is Long.MAX_VALUE, i.e. positive) throws IllegalArgumentException. In practice the check rejects every negative value except -1; zero and positive values proceed to the quota logic. The CLI guards most of this, so raw ClientProtocol/WebHDFS callers hit it.","triggerScenarios":"ClientProtocol.setQuota / WebHDFS SETQUOTA with a negative quota such as -5: scripts computing quota arithmetically (oldQuota - delta) that go below zero, or parsing '-1' style flags into the quota argument; dfsadmin validates client-side, so custom tooling and REST callers are the usual source.","commonSituations":"Automation deriving quotas from usage reports; Long values taken from config without validation; tools ported from the CLI that assumed argument checks happen server-side.","solutions":["Validate before the RPC: quota values must be >= 0 (use -1/QUOTA_RESET only via the dedicated clear operations that support it).","Fail fast in your wrapper: if (quota < 0 && quota != HdfsConstants.QUOTA_RESET) throw IllegalArgumentException with the offending value.","To clear quotas use 'hdfs dfsadmin -clrQuota'/'-clrSpaceQuota' or setQuota(path, HdfsConstants.QUOTA_RESET, ...) rather than inventing negative sentinels."],"exampleFix":"// before\ndfs.setQuota(path, computedQuota, HdfsConstants.QUOTA_DONT_SET);\n\n// after\nif (computedQuota < 0 && computedQuota != HdfsConstants.QUOTA_RESET) {\n  throw new IllegalArgumentException(\"nsQuota must be >= 0, got \" + computedQuota);\n}\ndfs.setQuota(path, computedQuota, HdfsConstants.QUOTA_DONT_SET);","handlingStrategy":"validation","validationCode":"static long checkedQuota(long q) {\n  if (q < 0 && q != HdfsConstants.QUOTA_RESET) {\n    throw new IllegalArgumentException(\"Quota must be >= 0, got \" + q);\n  }\n  return q;\n}\ndfs.setQuota(path, checkedQuota(nsQuota), checkedQuota(ssQuota));","typeGuard":null,"tryCatchPattern":"try {\n  dfs.setQuota(path, ns, ss);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"Illegal value for nsQuota\")) {\n    // your computed value went negative: fix the arithmetic, never resend unchanged\n  }\n}","preventionTips":["Wrap quota math in helpers that clamp or fail fast below zero.","Use the dedicated clear operations (-clrQuota / QUOTA_RESET) instead of ad hoc negative sentinels."],"tags":["hdfs","quota","validation","illegal-argument"],"backgroundTag":"invalid-quota-value","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}