{"record":{"id":"1c7443a5bdbc304e","repo":"apache/druid","slug":"invalid-format-or-out-of-range-of-long-s","errorCode":null,"errorMessage":"Invalid format or out of range of long: %s","messagePattern":"Invalid format or out of range of long: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/common/HumanReadableBytes.java","lineNumber":215,"sourceCode":"          throw new IAE(\"Invalid format of number: %s\", rawNumber);\n        }\n\n        //lastDigitIndex here holds the index which is prior to current digit\n        //move backward so that it's at the right place\n        lastDigitIndex++;\n        break;\n    }\n\n    try {\n      long value = Long.parseLong(number.substring(0, lastDigitIndex + 1)) * base;\n      if (base > 1 && value < base) {\n        //for base == 1, overflow has been checked in parseLong\n        throw new IAE(\"Number overflow: %s\", rawNumber);\n      }\n      return value;\n    }\n    catch (NumberFormatException e) {\n      throw new IAE(\"Invalid format or out of range of long: %s\", rawNumber);\n    }\n  }\n\n  public enum UnitSystem\n  {\n    /**\n     * also known as IEC format\n     * eg: B, KiB, MiB, GiB ...\n     */\n    BINARY_BYTE,\n\n    /**\n     * also known as SI format\n     * eg: B, KB, MB ...\n     */\n    DECIMAL_BYTE,\n\n    /**","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/common/HumanReadableBytes.java#L197-L233","documentation":"This is the fallback catch of NumberFormatException inside HumanReadableBytes.parse: the numeric substring itself is not a valid long (bad characters or too large for parseLong). It rethrows as an IAE telling you the input is either malformed or out of the long range. Distinct from the overflow check: here even the plain digit string could not be parsed.","triggerScenarios":"A number substring longer than 19 digits or otherwise unparseable (e.g. '1_000_000' with underscores, '1.5g' — decimals are not supported), or a value exceeding Long.MAX_VALUE before unit multiplication.","commonSituations":"Users writing decimal sizes like '1.5GB' or thousands separators '1,000,000'; extremely large auto-generated numbers; locale-formatted numbers with dots or commas.","solutions":["Remove decimal points, commas, underscores: use '1536m' instead of '1.5g'","Convert to an integer value in the chosen unit, e.g. '1.5GB' -> '1500MB'","Keep the raw digit string within Long.MAX_VALUE (<= 9223372036854775807)","Parse programmatically with Long.parseLong yourself first to pinpoint the bad character"],"exampleFix":"// before\nHumanReadableBytes.parse(\"1.5g\"); // IAE\n// after\nHumanReadableBytes.parse(\"1536m\");","handlingStrategy":"validation","validationCode":"static boolean isPlainLong(String s) {\n  return s != null && s.matches(\"-?\\\\d+\") && s.replace(\"-\", \"\").length() <= 19;\n}","typeGuard":"Long parsed = isPlainLong(numPart) ? Long.parseLong(numPart) : null;\nif (parsed == null) { throw new IllegalArgumentException(\"not a long: \" + s); }","tryCatchPattern":"try {\n  HumanReadableBytes bytes = HumanReadableBytes.parse(raw);\n} catch (IllegalArgumentException e) {\n  throw new IllegalArgumentException(\"Size must be an integer with optional unit, got: \" + raw, e);\n}","preventionTips":["Never use decimal points or thousands separators in size strings","Convert '1.5GB' style inputs to integer units before passing in","Sanitize locale-formatted numbers (strip '.'/',' groups) before parsing"],"tags":["parsing","number-format","bytes"],"backgroundTag":"invalid-argument-format","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}