apache/hadoop · error · IllegalArgumentException

${value} is not in expected format.Expected format is <numbe

Error message

${value} is not in expected format.Expected format is <number><unit>. e.g. 1000MB

What it means

After the blank check, StorageSize.parse() trims and lowercases the input, then scans StorageUnit values (EB..B, checked longest-short-name first) for a trailing unit via long name, short name, or suffix char. If none matches, it throws IllegalArgumentException demanding the <number><unit> form, e.g. "1000MB". The remaining numeric prefix is later consumed by Double.parseDouble.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/StorageSize.java:64

      throw new IllegalStateException(errorString);
    }
  }

  public static StorageSize parse(String value) {
    checkState(isNotBlank(value), "value cannot be blank");
    String sanitizedValue = value.trim().toLowerCase(Locale.ENGLISH);
    StorageUnit parsedUnit = null;
    for (StorageUnit unit : StorageUnit.values()) {
      if (sanitizedValue.endsWith(unit.getShortName()) ||
          sanitizedValue.endsWith(unit.getLongName()) ||
          sanitizedValue.endsWith(unit.getSuffixChar())) {
        parsedUnit = unit;
        break;
      }
    }

    if (parsedUnit == null) {
      throw new IllegalArgumentException(value + " is not in expected format." +
          "Expected format is <number><unit>. e.g. 1000MB");
    }


    String suffix = "";
    boolean found = false;

    // We are trying to get the longest match first, so the order of
    // matching is getLongName, getShortName and then getSuffixChar.
    if (!found && sanitizedValue.endsWith(parsedUnit.getLongName())) {
      found = true;
      suffix = parsedUnit.getLongName();
    }

    if (!found && sanitizedValue.endsWith(parsedUnit.getShortName())) {
      found = true;
      suffix = parsedUnit.getShortName();
    }

View on GitHub (pinned to 2add963021)

Solutions

  1. Append a supported unit, e.g. change 4096 to 4096MB
  2. Check the StorageUnit enum for accepted long names, short names, and suffix chars and correct the value to one of them
  3. When migrating legacy bare numbers, convert them programmatically to <number><unit> strings before parse

Example fix

<!-- before -->
<property><name>some.size.key</name><value>4096</value></property>

<!-- after -->
<property><name>some.size.key</name><value>4096MB</value></property>
Defensive patterns

Strategy: validation

Validate before calling

private static final Pattern SIZE = Pattern.compile(
    "^[0-9]+(\\.[0-9]+)?(b|kb|mb|gb|tb|pb|eb|bytes|kilobytes|megabytes|gigabytes|terabytes|petabytes|exabytes)$");

String v = raw.trim().toLowerCase(Locale.ENGLISH);
if (!SIZE.matcher(v).matches()) {
  throw new IllegalArgumentException(raw + " must be <number><unit>, e.g. 1000MB");
}
return StorageSize.parse(raw);

Try / catch

try {
  size = StorageSize.parse(raw);
} catch (IllegalArgumentException e) {
  throw new IllegalArgumentException(key + " has invalid value '" + raw + "'; expected <number><unit> like 1000MB", e);
}

Prevention

When it happens

Trigger: parse("4096") with no unit; parse("1000MiB") (IEC unit not a StorageUnit name); parse("foo"); parse("1tb2") — any string that does not end in a StorageUnit short name (b/kb/mb/gb/tb/pb/eb), long name (bytes/kilobytes/.../exabytes), or suffix char.

Common situations: Bare-number size values migrated from older configs or other tools that accepted unitless numbers; values copied from Linux docs using MiB/GiB; unit typos; trailing garbage after the unit.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/abd4d73a8ab0e55a. Report an issue: GitHub.