{"record":{"id":"5d7e1bde7987ee53","repo":"apache/hadoop","slug":"invalid-size-prefix-in-allowed-prefixes","errorCode":null,"errorMessage":"Invalid size prefix '{}' in '{}'. Allowed prefixes are k, m, g, t, p, e(case insensitive)","messagePattern":"Invalid size prefix '(.+?)' in '(.+?)'\\. Allowed prefixes are k, m, g, t, p, e\\(case insensitive\\)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java","lineNumber":917,"sourceCode":"     * For example,\n     * \"-1230k\" will be converted to -1230 * 1024 = -1259520;\n     * \"891g\" will be converted to 891 * 1024^3 = 956703965184;\n     *\n     * @param s input string\n     * @return a long value represented by the input string.\n     */\n    public static long string2long(String s) {\n      s = s.trim();\n      final int lastpos = s.length() - 1;\n      final char lastchar = s.charAt(lastpos);\n      if (Character.isDigit(lastchar))\n        return Long.parseLong(s);\n      else {\n        long prefix;\n        try {\n          prefix = TraditionalBinaryPrefix.valueOf(lastchar).value;\n        } catch (IllegalArgumentException e) {\n          throw new IllegalArgumentException(\"Invalid size prefix '\" + lastchar\n              + \"' in '\" + s\n              + \"'. Allowed prefixes are k, m, g, t, p, e(case insensitive)\");\n        }\n        long num = Long.parseLong(s.substring(0, lastpos));\n        if (num > (Long.MAX_VALUE/prefix) || num < (Long.MIN_VALUE/prefix)) {\n          throw new IllegalArgumentException(s + \" does not fit in a Long\");\n        }\n        return num * prefix;\n      }\n    }\n\n    /**\n     * Convert a long integer to a string with traditional binary prefix.\n     * \n     * @param n the value to be converted\n     * @param unit The unit, e.g. \"B\" for bytes.\n     * @param decimalPlaces The number of decimal places.\n     * @return a string with traditional binary prefix.","sourceCodeStart":899,"sourceCodeEnd":935,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java#L899-L935","documentation":"StringUtils.string2long trims the input, and if the last character is a digit it parses the whole string as a long; otherwise it looks the last character up as a traditional binary prefix. When that lookup fails (any character other than k, m, g, t, p, e, case-insensitive), the IllegalArgumentException from valueOf is caught and rethrown with this message telling you the allowed prefixes. This is the friendly wrapper around the 'Unknown symbol' error (error 1840).","triggerScenarios":"string2long(\"1KB\") — 'B' is not a prefix; string2long(\"abc\") — 'c' is not a valid prefix letter; string2long(\"10GiB\") — 'i'... actually last char 'B' invalid; string2long(\"5x\"); any input whose final character is a non-digit outside the allowed set. Note: if the prefix letter is valid but the leading part is not numeric (e.g. '12abg'), you get NumberFormatException from Long.parseLong instead, not this error.","commonSituations":"Memory/size configuration values written with a byte unit ('512mb', '2gb') instead of Hadoop's bare prefix ('512m', '2g'); copying SI units ('1KiB') or network-style units ('10Mb') into configs parsed by string2long; trailing unit characters like '%' or 'B' from templated config files.","solutions":["Rewrite the value with a valid bare prefix: '512m', '2g', '1t' (k=1024, m=1024^2, g=1024^3, t=1024^4, p=1024^5, e=1024^6).","Remove trailing 'b'/'B' from generated config values before they reach string2long.","Pre-validate input with a regex such as ^-?\\d+[kKmMgGtTpPeE]?$ before calling string2long so you control the error message.","Wrap the call in try/catch IllegalArgumentException to produce a config-validation error naming the offending property."],"exampleFix":"// before\nlong v = StringUtils.string2long(conf.get(\"mapred.task.mem\", \"512mb\"));\n// throws: Invalid size prefix 'B' in '512mb'\n\n// after\nlong v = StringUtils.string2long(conf.get(\"mapred.task.mem\", \"512m\"));","handlingStrategy":"validation","validationCode":"private static final Pattern SIZE = Pattern.compile(\"^-?\\d+([kKmMgGtTpPeE])?$\");\n\nstatic boolean isParsableSize(String s) {\n  return s != null && SIZE.matcher(s.trim()).matches();\n}\n\n// use before StringUtils.string2long\nif (!isParsableSize(val)) {\n  throw new IllegalArgumentException(\"Property value '\" + val\n      + \"' must be a number optionally suffixed with k/m/g/t/p/e\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  long bytes = StringUtils.string2long(value);\n} catch (IllegalArgumentException e) {\n  LOG.error(\"Bad size value '\" + value + \"' for property \" + propName, e);\n  throw new ConfigurationException(propName, e.getMessage());\n}","preventionTips":["Document accepted suffixes (k, m, g, t, p, e — no 'b') wherever size configs are exposed.","Reject values with unit words ('mb', 'gb') at config load with a clear message.","Add unit tests covering suffix variants to catch regressions in config generators."],"tags":["string-parsing","binary-prefix","size-units","configuration","hadoop-common"],"backgroundTag":"invalid-size-suffix","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}