apache/hadoop · error · IllegalArgumentException

Unknown symbol '{}'

Error message

Unknown symbol '{}'

What it means

Thrown by StringUtils.TraditionalBinaryPrefix.valueOf(char), this IllegalArgumentException means the character is not one of the six traditional binary prefix symbols k, m, g, t, p, e (1024^1 through 1024^6; case-insensitive because the char is upper-cased before matching). It is the low-level lookup that StringUtils.string2long uses to parse values like '891g', so any unrecognized trailing letter (e.g. 'b', 'i', 'x', 'c') reaches this throw. Most callers instead see the wrapped 'Invalid size prefix' message from string2long; you only see this raw message when calling valueOf directly.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java:891

      this.value = 1L << bitShift;
      this.bitMask = this.value - 1L;
      this.symbol = toString().charAt(0);
    }

    /**
     * The TraditionalBinaryPrefix object corresponding to the symbol.
     *
     * @param symbol symbol.
     * @return traditional binary prefix object.
     */
    public static TraditionalBinaryPrefix valueOf(char symbol) {
      symbol = Character.toUpperCase(symbol);
      for(TraditionalBinaryPrefix prefix : TraditionalBinaryPrefix.values()) {
        if (symbol == prefix.symbol) {
          return prefix;
        }
      }
      throw new IllegalArgumentException("Unknown symbol '" + symbol + "'");
    }

    /**
     * Convert a string to long.
     * The input string is first be trimmed
     * and then it is parsed with traditional binary prefix.
     *
     * For example,
     * "-1230k" will be converted to -1230 * 1024 = -1259520;
     * "891g" will be converted to 891 * 1024^3 = 956703965184;
     *
     * @param s input string
     * @return a long value represented by the input string.
     */
    public static long string2long(String s) {
      s = s.trim();
      final int lastpos = s.length() - 1;
      final char lastchar = s.charAt(lastpos);

View on GitHub (pinned to 2add963021)

Solutions

  1. Use only k, m, g, t, p, or e as the trailing prefix (case-insensitive): '512m' or '512M', never '512mb'.
  2. Strip a trailing 'b'/'B' from input before calling string2long if your data carries byte units.
  3. Call StringUtils.string2long instead of TraditionalBinaryPrefix.valueOf directly, so you get the message listing the allowed prefixes.
  4. If you must call valueOf yourself, catch IllegalArgumentException and surface your own validation error naming the bad symbol.

Example fix

// before
long bytes = StringUtils.string2long("512mb");
// -> valueOf('B') throws "Unknown symbol 'B'" via the wrapped message

// after
long bytes = StringUtils.string2long("512m"); // 512 * 1024^2
Defensive patterns

Strategy: validation

Validate before calling

static boolean isValidBinaryPrefixChar(char c) {
  char u = Character.toUpperCase(c);
  return u == 'K' || u == 'M' || u == 'G'
      || u == 'T' || u == 'P' || u == 'E';
}

// use: strip optional trailing 'b'/'B', then validate before valueOf
String s = input.trim();
if (s.toUpperCase().endsWith("B") && s.length() > 1) {
  s = s.substring(0, s.length() - 1);
}
char last = s.charAt(s.length() - 1);
if (!Character.isDigit(last) && !isValidBinaryPrefixChar(last)) {
  throw new IllegalArgumentException("Bad size suffix in: " + input);
}

Try / catch

try {
  long v = StringUtils.TraditionalBinaryPrefix.valueOf(c).value;
} catch (IllegalArgumentException e) {
  // reject input, surface allowed symbols k/m/g/t/p/e
  throw new ConfigException("invalid size symbol: " + c, e);
}

Prevention

When it happens

Trigger: Calling TraditionalBinaryPrefix.valueOf('b'), valueOf('i'), or valueOf('x') directly; indirectly via StringUtils.string2long('10kb') or string2long('5b') where the last character is neither a digit nor k/m/g/t/p/e; a custom parser that strips a unit string down to one letter and passes it to valueOf.

Common situations: Hadoop size/memory strings that carry a byte unit ('512mb', '10gb') — only the single-letter prefix is understood, so 'B' suffixes fail; SI-style abbreviations like '1GiB' (the 'i' is rejected); migrating code from a parser that accepted 'kb'/'Kb' forms; typos such as '89lG' where the last char is a letter other than the six prefixes.

Related errors


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