{"record":{"id":"3e488d54ebe9dbb0","repo":"apache/druid","slug":"key-s-should-be-an-int-was-s","errorCode":null,"errorMessage":"Key[%s] should be an int, was[%s]","messagePattern":"Key\\[(.+?)\\] should be an int, was\\[(.+?)\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/common/MapUtils.java","lineNumber":64,"sourceCode":"  }\n\n  public static int getInt(Map<String, Object> in, String key, Integer defaultValue)\n  {\n    Object retVal = in.get(key);\n\n    if (retVal == null) {\n      if (defaultValue == null) {\n        throw new IAE(\"Key[%s] is required in map[%s]\", key, in);\n      }\n\n      return defaultValue;\n    }\n\n    try {\n      return Integer.parseInt(retVal.toString());\n    }\n    catch (NumberFormatException e) {\n      throw new IAE(e, \"Key[%s] should be an int, was[%s]\", key, retVal);\n    }\n  }\n\n  public static long getLong(Map<String, Object> in, String key, Long defaultValue)\n  {\n    Object retVal = in.get(key);\n\n    if (retVal == null) {\n      if (defaultValue == null) {\n        throw new IAE(\"Key[%s] is required in map[%s]\", key, in);\n      }\n\n      return defaultValue;\n    }\n\n    try {\n      return Long.parseLong(retVal.toString());\n    }","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/common/MapUtils.java#L46-L82","documentation":"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.","triggerScenarios":"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\").","commonSituations":"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.","solutions":["Correct the value in the map/config to a plain integer string (e.g. \"1024\")","Strip units/whitespace before storing: value.replaceAll(\"[^0-9-]\", \"\")","Use a different accessor if the value is fractional (getLong/double) or parse it yourself","Add validation at config load time to fail early with a clearer message"],"exampleFix":"// before\nmap.put(\"druid.maxRows\", \"1,000\");\nint rows = MapUtils.getInt(map, \"druid.maxRows\", 0);\n// after\nmap.put(\"druid.maxRows\", \"1000\");\nint rows = MapUtils.getInt(map, \"druid.maxRows\", 0);","handlingStrategy":"validation","validationCode":"Object v = map.get(key);\nif (v != null && !v.toString().trim().matches(\"-?\\\\d+\")) {\n  throw new IllegalArgumentException(\"Key \" + key + \" must be an integer, got: \" + v);\n}","typeGuard":"static boolean isIntString(Object v) {\n  return v != null && v.toString().trim().matches(\"-?\\\\d+\");\n}","tryCatchPattern":"try {\n  return MapUtils.getInt(map, key, defaultVal);\n} catch (IllegalArgumentException e) {\n  log.error(\"Bad int for %s: %s\", key, e.getMessage());\n  return defaultVal;\n}","preventionTips":["Store config numbers as plain integer strings, no units or separators","Reject unit-suffixed values at config load time","Trim whitespace before storing values","Add startup validation that parses all numeric properties once"],"tags":["configuration","number-format","type-mismatch"],"backgroundTag":"invalid-config-value","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}