apache/druid · error · IllegalArgumentException

Key[ ] should be an int, was[ ]

Error message

Key[%s] should be an int, was[%s]

What it means

MapUtils.getInt found the key but its value's toString() could not be parsed by Integer.parseInt. The utility throws IAE (wrapping the NumberFormatException) naming the key and the offending value, so callers know exactly which config entry is malformed.

Solutions

  1. Correct the value in the map/config to a plain integer string (e.g. "1024")
  2. Strip units/whitespace before storing: value.replaceAll("[^0-9-]", "")
  3. Use a different accessor if the value is fractional (getLong/double) or parse it yourself
  4. Add validation at config load time to fail early with a clearer message

Example fix

// before
map.put("druid.maxRows", "1,000");
int rows = MapUtils.getInt(map, "druid.maxRows", 0);
// after
map.put("druid.maxRows", "1000");
int rows = MapUtils.getInt(map, "druid.maxRows", 0);
Defensive patterns

Strategy: validation

Validate before calling

Object v = map.get(key);
if (v != null && !v.toString().trim().matches("-?\\d+")) {
  throw new IllegalArgumentException("Key " + key + " must be an integer, got: " + v);
}

Type guard

static boolean isIntString(Object v) {
  return v != null && v.toString().trim().matches("-?\\d+");
}

Try / catch

try {
  return MapUtils.getInt(map, key, defaultVal);
} catch (IllegalArgumentException e) {
  log.error("Bad int for %s: %s", key, e.getMessage());
  return defaultVal;
}

Prevention

When it happens

Trigger: Calling MapUtils.getInt(map, key, defaultValue) where map.get(key) is a non-null object whose string form is not a valid int (e.g. "abc", "1.5", "12,000", "", "true").

Common situations: Config values written as "1024M" or "1_000", decimals in an int field, whitespace or thousands separators, or a JSON value that is a string with extra characters.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/java/util/common/MapUtils.java:64

  }

  public static int getInt(Map<String, Object> in, String key, Integer defaultValue)
  {
    Object retVal = in.get(key);

    if (retVal == null) {
      if (defaultValue == null) {
        throw new IAE("Key[%s] is required in map[%s]", key, in);
      }

      return defaultValue;
    }

    try {
      return Integer.parseInt(retVal.toString());
    }
    catch (NumberFormatException e) {
      throw new IAE(e, "Key[%s] should be an int, was[%s]", key, retVal);
    }
  }

  public static long getLong(Map<String, Object> in, String key, Long defaultValue)
  {
    Object retVal = in.get(key);

    if (retVal == null) {
      if (defaultValue == null) {
        throw new IAE("Key[%s] is required in map[%s]", key, in);
      }

      return defaultValue;
    }

    try {
      return Long.parseLong(retVal.toString());
    }

View on GitHub (pinned to 9b90983fd2)