apache/druid · error · IllegalArgumentException

Invalid format of number: %s. Negative value is not allowed.

Error message

Invalid format of number: %s. Negative value is not allowed.

What it means

HumanReadableBytes.parse (via parseInner) throws this IllegalArgumentException for values that start with '-'. Negative byte sizes are meaningless in this library, so any signed input is rejected before further parsing.

Source

Thrown at processing/src/main/java/org/apache/druid/java/util/common/HumanReadableBytes.java:147

   */
  public static long parse(String number, long nullValue)
  {
    if (number == null) {
      return nullValue;
    }

    number = number.trim();
    if (number.length() == 0) {
      return nullValue;
    }
    return parseInner(number);
  }

  private static long parseInner(String rawNumber)
  {
    String number = StringUtils.toLowerCase(rawNumber);
    if (number.charAt(0) == '-') {
      throw new IAE("Invalid format of number: %s. Negative value is not allowed.", rawNumber);
    }

    int lastDigitIndex = number.length() - 1;
    boolean isBinaryByte = false;
    char unit = number.charAt(lastDigitIndex--);
    if (unit == 'b') {
      //unit ends with 'b' must be format of KiB/MiB/GiB/TiB/PiB, so at least 3 extra characters are required
      if (lastDigitIndex < 2) {
        throw new IAE("Invalid format of number: %s", rawNumber);
      }
      if (number.charAt(lastDigitIndex--) != 'i') {
        throw new IAE("Invalid format of number: %s", rawNumber);
      }

      unit = number.charAt(lastDigitIndex--);
      isBinaryByte = true;
    } else if (unit == 'i') {
      //unit ends with 'i' must be format of Ki/Mi/Gi/Ti/Pi, so at least 2 extra characters are required

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Remove the minus sign and provide a positive size like "100mb"
  2. Validate the configured value is non-negative before parsing
  3. Check the templating/concatenation logic that introduced the leading '-'
  4. Catch IAE at config-load time and fail with a clearer message naming the property

Example fix

// before
long bytes = HumanReadableBytes.parse("-512mb");
// after
long bytes = HumanReadableBytes.parse("512mb");
Defensive patterns

Strategy: validation

Validate before calling

if (raw != null && raw.trim().startsWith("-")) {
  throw new IllegalArgumentException("Byte size must be non-negative: " + raw);
}
long bytes = HumanReadableBytes.parse(raw);

Type guard

static boolean isNonNegativeSize(String s) {
  return s != null && !s.trim().startsWith("-");
}

Try / catch

try {
  long bytes = HumanReadableBytes.parse(raw);
} catch (IAE e) {
  throw new IllegalArgumentException("Configured byte size must be positive, got: " + raw, e);
}

Prevention

When it happens

Trigger: Calling HumanReadableBytes.parse("-100mb") or any string whose first character after lowercasing is '-'.

Common situations: Accidental leading hyphen from concatenating flags and values; templating mistakes producing "-${SIZE}"; users expecting signed/relative sizes to be supported.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/4908fef669a0f2e3. Report an issue: GitHub.