apache/druid · error · IllegalArgumentException

Invalid format or out of range of long

Error message

Invalid format or out of range of long: %s

What it means

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.

Solutions

  1. Remove decimal points, commas, underscores: use '1536m' instead of '1.5g'
  2. Convert to an integer value in the chosen unit, e.g. '1.5GB' -> '1500MB'
  3. Keep the raw digit string within Long.MAX_VALUE (<= 9223372036854775807)
  4. Parse programmatically with Long.parseLong yourself first to pinpoint the bad character

Example fix

// before
HumanReadableBytes.parse("1.5g"); // IAE
// after
HumanReadableBytes.parse("1536m");
Defensive patterns

Strategy: validation

Validate before calling

static boolean isPlainLong(String s) {
  return s != null && s.matches("-?\\d+") && s.replace("-", "").length() <= 19;
}

Type guard

Long parsed = isPlainLong(numPart) ? Long.parseLong(numPart) : null;
if (parsed == null) { throw new IllegalArgumentException("not a long: " + s); }

Try / catch

try {
  HumanReadableBytes bytes = HumanReadableBytes.parse(raw);
} catch (IllegalArgumentException e) {
  throw new IllegalArgumentException("Size must be an integer with optional unit, got: " + raw, e);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

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

          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
     * eg: B, KB, MB ...
     */
    DECIMAL_BYTE,

    /**

View on GitHub (pinned to 9b90983fd2)