{"record":{"id":"fda8085b391bb247","repo":"apache/druid","slug":"key-s-should-be-a-long-was-s","errorCode":null,"errorMessage":"Key[%s] should be a long, was[%s]","messagePattern":"Key\\[(.+?)\\] should be a long, was\\[(.+?)\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/common/MapUtils.java","lineNumber":84,"sourceCode":"  }\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    }\n    catch (NumberFormatException e) {\n      throw new IAE(e, \"Key[%s] should be a long, was[%s]\", key, retVal);\n    }\n  }\n\n}\n","sourceCodeStart":66,"sourceCodeEnd":89,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/common/MapUtils.java#L66-L89","documentation":"MapUtils.getLong found the key but its string representation could not be parsed by Long.parseLong. It throws IAE wrapping the NumberFormatException, naming the key and the actual value so the malformed entry is easy to locate.","triggerScenarios":"Calling MapUtils.getLong(map, key, defaultValue) where the stored value's toString() is not a valid long (e.g. \"10.5\", \"8GB\", \"1e9\", empty string, boolean).","commonSituations":"Byte-size strings like \"10GB\" in a field expecting raw bytes, decimal numbers, scientific notation, or stray whitespace/characters in properties files.","solutions":["Fix the value to a plain integer literal (e.g. \"10737418240\" instead of \"10GB\")","Convert units yourself before storing: 10L * 1024 * 1024 * 1024","Parse with a helper that understands unit suffixes if such values are expected","Validate the config at startup with clear errors for each bad entry"],"exampleFix":"// before\nprops.put(\"druid.segment.cache.sizeBytes\", \"5GB\");\nlong size = MapUtils.getLong(props, \"druid.segment.cache.sizeBytes\", 0L);\n// after\nprops.put(\"druid.segment.cache.sizeBytes\", Long.toString(5L * 1024 * 1024 * 1024));\nlong size = MapUtils.getLong(props, \"druid.segment.cache.sizeBytes\", 0L);","handlingStrategy":"validation","validationCode":"Object v = props.get(key);\nif (v != null && !v.toString().trim().matches(\"-?\\\\d+\")) {\n  throw new IllegalArgumentException(\"Key \" + key + \" must be a whole number (long), got: \" + v);\n}","typeGuard":"static boolean isLongString(Object v) {\n  return v != null && v.toString().trim().matches(\"-?\\\\d+\");\n}","tryCatchPattern":"try {\n  return MapUtils.getLong(props, key, defaultVal);\n} catch (IllegalArgumentException e) {\n  log.error(\"Invalid long value for %s\", key, e);\n  return defaultVal;\n}","preventionTips":["Convert human-readable sizes (e.g. 5GB) to raw byte counts before storing","Avoid decimals and scientific notation in long fields","Validate all numeric properties once at startup","Keep numeric config values machine-readable"],"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"}