apache/druid · error · IllegalArgumentException

Number overflow

Error message

Number overflow: %s

What it means

After multiplying the parsed numeric value by the unit base, the result no longer fits in a long (or wrapped around), so HumanReadableBytes throws this IAE. The check is: when base > 1, the product must be >= base; a product smaller than base means long overflow occurred during multiplication. Values that already exceed Long.MAX_VALUE at parseLong time are caught separately by the NumberFormatException branch.

Solutions

  1. Reduce the number so value * base fits in a long (max raw value is Long.MAX_VALUE / base)
  2. Use a smaller unit suffix: '9223372036854775807' bytes is fine, but scale down 't'/'p' values
  3. Verify you did not mean a decimal unit where binary was used or vice versa (e.g. '10P' vs '10PiB')

Example fix

// before
HumanReadableBytes.parse("9999999999999t"); // overflow
// after
HumanReadableBytes.parse("8388608t"); // < Long.MAX_VALUE
Defensive patterns

Strategy: validation

Validate before calling

static boolean fitsInLong(String s) {
  try {
    HumanReadableBytes h = HumanReadableBytes.parse(s);
    return h.getBytes() >= 0;
  } catch (IllegalArgumentException e) { return false; }
}

Type guard

if (value > Long.MAX_VALUE / baseFor(unit)) { throw new IllegalArgumentException("too large: " + s); }

Try / catch

try {
  long bytes = HumanReadableBytes.valueOf(raw).getBytes();
} catch (IllegalArgumentException e) {
  log.warn("Size [%s] overflows long, clamping", raw);
  bytes = Long.MAX_VALUE;
}

Prevention

When it happens

Trigger: Parsing a value whose magnitude times the unit base exceeds Long.MAX_VALUE, e.g. '9223372036854775807t' or '100P' with a binary base near the top of the long range; also huge literal numbers like '99999999999999999999'.

Common situations: Misconfigured size properties where someone typed gigabytes expecting megabytes ('9999999999g'), or auto-generated configs scaling a value into overflow; binary vs decimal base selection amplifying an already large number.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

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

        base = isBinaryByte ? 1024L * 1024 * 1024 * 1024 * 1024 : 1_000_000_000_000_000L;
        break;

      default:
        if (!Character.isDigit(unit)) {
          throw new IAE("Invalid format of number: %s", rawNumber);
        }

        //lastDigitIndex here holds the index which is prior to current digit
        //move backward so that it's at the right place
        lastDigitIndex++;
        break;
    }

    try {
      long value = Long.parseLong(number.substring(0, lastDigitIndex + 1)) * base;
      if (base > 1 && value < base) {
        //for base == 1, overflow has been checked in parseLong
        throw new IAE("Number overflow: %s", rawNumber);
      }
      return value;
    }
    catch (NumberFormatException e) {
      throw new IAE("Invalid format or out of range of long: %s", rawNumber);
    }
  }

  public enum UnitSystem
  {
    /**
     * also known as IEC format
     * eg: B, KiB, MiB, GiB ...
     */
    BINARY_BYTE,

    /**
     * also known as SI format

View on GitHub (pinned to 9b90983fd2)