{"record":{"id":"d3d5299abf9c25e2","repo":"grpc/grpc-java","slug":"value-s-for-key-s-is-not-a-long-integer","errorCode":null,"errorMessage":"value '%s' for key '%s' is not a long integer","messagePattern":"value '(.+?)' for key '(.+?)' is not a long integer","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/grpc/internal/JsonUtil.java","lineNumber":178,"sourceCode":"  public static Long getNumberAsLong(Map<String, ?> obj, String key) {\n    assert key != null;\n    if (!obj.containsKey(key)) {\n      return null;\n    }\n    Object value = obj.get(key);\n    if (value instanceof Double) {\n      Double d = (Double) value;\n      long l = d.longValue();\n      if (l != d) {\n        throw new ClassCastException(\"Number expected to be long: \" + d);\n      }\n      return l;\n    }\n    if (value instanceof String) {\n      try {\n        return Long.parseLong((String) value);\n      } catch (NumberFormatException e) {\n        throw new IllegalArgumentException(\n            String.format(\"value '%s' for key '%s' is not a long integer\", value, key));\n      }\n    }\n    throw new IllegalArgumentException(\n        String.format(\"value '%s' for key '%s' is not a long integer\", value, key));\n  }\n\n  /**\n   * Gets a string from an object for the given key.  If the key is not present, this returns null.\n   * If the value is not a String, throws an exception.\n   */\n  @Nullable\n  public static String getString(Map<String, ?> obj, String key) {\n    assert key != null;\n    if (!obj.containsKey(key)) {\n      return null;\n    }\n    Object value = obj.get(key);","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/core/src/main/java/io/grpc/internal/JsonUtil.java#L160-L196","documentation":"getNumberAsLong accepts string-encoded longs, parsed with Long.parseLong. A String that cannot be parsed (wrong characters, decimal point, overflow) produces IllegalArgumentException 'value ... is not a long integer'. This keeps long config fields strictly validated.","triggerScenarios":"JsonUtil.getNumberAsLong(map, key) with a String value like \"abc\", \"1.5\", \"99999999999999999999\" (overflow past Long.MAX_VALUE), or a signed/whitespace-polluted string.","commonSituations":"Quoted numbers in service config JSON; 64-bit values pasted from other systems with formatting (commas \"1,000,000\"); values exceeding Long.MAX_VALUE such as unsigned 64-bit IDs.","solutions":["Fix the string to a valid signed 64-bit decimal integer (strip commas/units, remove decimal point).","If the number exceeds Long range, restructure the config (e.g. split high/low words or use a smaller unit).","Pre-validate with Long.parseLong in your own loader to raise a clearer error."],"exampleFix":"// before\n{\"flowControlWindow\": \"1,048,576\"}\n// after\n{\"flowControlWindow\": 1048576}","handlingStrategy":"validation","validationCode":"Object v = config.get(\"flowControlWindow\");\nif (v instanceof String) {\n  try { Long.parseLong((String) v); }\n  catch (NumberFormatException e) { throw new IllegalArgumentException(\"flowControlWindow is not a long\"); }\n}","typeGuard":"boolean isLongString(Object v) {\n  if (!(v instanceof String)) return false;\n  try { Long.parseLong((String) v); return true; } catch (NumberFormatException e) { return false; }\n}","tryCatchPattern":"try {\n  long l = JsonUtil.getNumberAsLong(config, \"flowControlWindow\");\n} catch (IllegalArgumentException e) {\n  log.error(\"Invalid long value in config: \" + e.getMessage());\n}","preventionTips":["Strip separators (commas, spaces, units) from 64-bit values in config pipelines.","Reject values beyond Long.MAX_VALUE at load time.","Write large numbers unquoted in JSON."],"tags":["grpc","json","config","format"],"backgroundTag":"invalid-argument-format","analyzedSha":"64daddc1f3d1975670f769f3e97bde8b2ba32d25","analyzedAt":"2026-09-08T06:14:57.704Z","contentChangedAt":"2026-09-08T06:14:57.704Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}