{"record":{"id":"a076be31cf0908e2","repo":"grpc/grpc-java","slug":"value-s-for-idx-d-in-s-is-not-object","errorCode":null,"errorMessage":"value %s for idx %d in %s is not object","messagePattern":"value (.+?) for idx (.+?) in (.+?) is not object","errorType":"validation","errorClass":"ClassCastException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/grpc/internal/JsonUtil.java","lineNumber":247,"sourceCode":"      return null;\n    }\n    Object value = obj.get(key);\n    if (!(value instanceof Boolean)) {\n      throw new ClassCastException(\n          String.format(\"value '%s' for key '%s' in '%s' is not Boolean\", value, key, obj));\n    }\n    return (Boolean) value;\n  }\n\n  /**\n   * Casts a list of unchecked JSON values to a list of checked objects in Java type.\n   * If the given list contains a value that is not a Map, throws an exception.\n   */\n  @SuppressWarnings(\"unchecked\")\n  public static List<Map<String, ?>> checkObjectList(List<?> rawList) {\n    for (int i = 0; i < rawList.size(); i++) {\n      if (!(rawList.get(i) instanceof Map)) {\n        throw new ClassCastException(\n            String.format(\n                Locale.US, \"value %s for idx %d in %s is not object\", rawList.get(i), i, rawList));\n      }\n    }\n    return (List<Map<String, ?>>) rawList;\n  }\n\n  /**\n   * Casts a list of unchecked JSON values to a list of String. If the given list\n   * contains a value that is not a String, throws an exception.\n   */\n  @SuppressWarnings(\"unchecked\")\n  public static List<String> checkStringList(List<?> rawList) {\n    for (int i = 0; i < rawList.size(); i++) {\n      if (!(rawList.get(i) instanceof String)) {\n        throw new ClassCastException(\n            String.format(\n                Locale.US,","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/core/src/main/java/io/grpc/internal/JsonUtil.java#L229-L265","documentation":"checkObjectList validates that every element of a JSON list is a Map (a JSON object) and returns the list cast to List<Map<String, ?>>. Any non-object element triggers ClassCastException 'value ... is not object' with the index and full list. Used for list-of-object config fields like retry/ hedging policy lists.","triggerScenarios":"JsonUtil.checkObjectList(rawList) — reached via getListOfObjects — where the list contains a scalar or array element, e.g. \"retryPolicy\": [1,2] instead of [{...}].","commonSituations":"Service config where an array of objects was flattened into an array of scalars; a mix like [{...}, \"oops\"]; upstream API returning a differently shaped list than the config schema expects.","solutions":["Wrap each element of the list in an object: [1,2] -> [{...}] per the gRPC service config schema.","Look at the printed index in the message to find exactly which element is wrong.","Validate the list-of-objects shape with JSON Schema before parsing."],"exampleFix":"// before\n{\"methodConfig\": [3, 5]}\n// after\n{\"methodConfig\": [{\"name\": [{}]}]}","handlingStrategy":"validation","validationCode":"Object v = config.get(\"methodConfig\");\nif (v instanceof List) {\n  for (Object e : (List<?>) v) {\n    if (!(e instanceof Map)) {\n      throw new IllegalArgumentException(\"methodConfig elements must be objects, got: \" + e);\n    }\n  }\n}","typeGuard":"boolean isListOfObjects(Object v) {\n  return v instanceof List && ((List<?>) v).stream().allMatch(e -> e instanceof Map);\n}","tryCatchPattern":"try {\n  List<Map<String, ?>> l = JsonUtil.checkObjectList(rawList);\n} catch (ClassCastException e) {\n  log.error(\"List-of-objects config field malformed: \" + e.getMessage());\n}","preventionTips":["Follow the gRPC service config schema for list fields exactly.","Schema-validate arrays-of-objects before parsing.","Check upstream API responses against expected shapes."],"tags":["grpc","json","config","type"],"backgroundTag":"schema-validation-failed","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"}