{"record":{"id":"dc1299672ec3aca0","repo":"apache/hadoop","slug":"is-not-a-valid-value-for-a-quota","errorCode":null,"errorMessage":"\"{}\" is not a valid value for a quota.","messagePattern":"\"(.+?)\" is not a valid value for a quota\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java","lineNumber":327,"sourceCode":"        \"\\t\\t- DISK\\n\" +\n        \"\\t\\t- SSD\\n\" +\n        \"\\t\\t- ARCHIVE\\n\" +\n        \"\\t\\t- PROVIDED\\n\" +\n        \"\\t\\t- NVDIMM\";\n\n    private long quota; // the quota to be set\n    private StorageType type;\n    \n    /** Constructor */\n    SetSpaceQuotaCommand(String[] args, int pos, Configuration conf) {\n      super(conf);\n      CommandFormat c = new CommandFormat(2, Integer.MAX_VALUE);\n      List<String> parameters = c.parse(args, pos);\n      String str = parameters.remove(0).trim();\n      try {\n        quota = StringUtils.TraditionalBinaryPrefix.string2long(str);\n      } catch (NumberFormatException nfe) {\n        throw new IllegalArgumentException(\"\\\"\" + str + \"\\\" is not a valid value for a quota.\");\n      }\n      String storageTypeString =\n          StringUtils.popOptionWithArgument(\"-storageType\", parameters);\n      if (storageTypeString != null) {\n        try {\n          this.type = StorageType.parseStorageType(storageTypeString);\n        } catch (IllegalArgumentException e) {\n          throw new IllegalArgumentException(\"Storage type \"\n              + storageTypeString\n              + \" is not available. Available storage types are \"\n              + StorageType.getTypesSupportingQuota());\n        }\n      }\n      this.args = parameters.toArray(new String[parameters.size()]);\n    }\n    \n    /** Check if a command is the setQuota command\n     * ","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java#L309-L345","documentation":"Constructor argument parser for `hdfs dfsadmin -setSpaceQuota <quota> <path>...`. The first positional argument is parsed with StringUtils.TraditionalBinaryPrefix.string2long, which accepts plain integers and binary-prefixed values (1k, 1m, 1g, 1t, 1p). Anything else raises NumberFormatException, rethrown as IllegalArgumentException('\"<str>\" is not a valid value for a quota.') with the offending string quoted for easy spotting.","triggerScenarios":"hdfs dfsadmin -setSpaceQuota abc /data; -setSpaceQuota 10XB /data (bad suffix); -setSpaceQuota 1,000,000 /data (commas); shell quoting that passes an empty string as the first parameter.","commonSituations":"Scripts feeding human-formatted numbers or SI units (1MB, 10GB with 'B'); users trying 'none' or 'unlimited' (not valid here — use -clrSpaceQuota); copy-paste of nameservice quotas from a doc into the CLI.","solutions":["Pass a plain byte count or a binary-prefix value: 1099511627776 or 1t","Normalize user input before invoking the CLI: strip commas/spaces, reject non suffix values","To remove a quota use hdfs dfsadmin -clrSpaceQuota <path>","Validate with TraditionalBinaryPrefix.string2long() in a try/catch before spawning the command"],"exampleFix":"# before\n$ hdfs dfsadmin -setSpaceQuota 1TB /data\n# IllegalArgumentException: \"1TB\" is not a valid value for a quota.\n\n# after\n$ hdfs dfsadmin -setSpaceQuota 1t /data\n$ hdfs dfsadmin -setSpaceQuota 1099511627776 /data   # equivalent plain bytes","handlingStrategy":"validation","validationCode":"static long parseQuota(String raw) {\n  try {\n    return StringUtils.TraditionalBinaryPrefix.string2long(raw.trim());\n  } catch (NumberFormatException e) {\n    throw new IllegalArgumentException(\"'\" + raw + \"' is not a quota; use 1024, 10m, 1t ...\", e);\n  }\n}","typeGuard":"static boolean isValidQuota(String s) {\n  try { StringUtils.TraditionalBinaryPrefix.string2long(s.trim()); return true; }\n  catch (NumberFormatException e) { return false; }\n}","tryCatchPattern":"catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"not a valid value for a quota\"))\n    return usage(\"quota must be a long or binary-prefixed value like 1t\");\n  throw e;\n}","preventionTips":["Normalize user input before spawning dfsadmin: strip commas, reject unit suffixes with 'B'","Remember only k/m/g/t/p (and plain longs) parse — 1MB, 1TB, 'none' do not","Use -clrSpaceQuota to remove a quota, never a magic value"],"tags":["hdfs","dfsadmin","quota","cli","argument-parsing","number-format"],"backgroundTag":"invalid-number-format","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}