{"record":{"id":"178ffb96ed687614","repo":"grpc/grpc-java","slug":"wrong-type","errorCode":null,"errorMessage":"wrong type ","messagePattern":"wrong type ","errorType":"validation","errorClass":"ClassCastException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/grpc/internal/DnsNameResolver.java","lineNumber":406,"sourceCode":"    return port;\n  }\n\n  /**\n   * Parse TXT service config records as JSON.\n   *\n   * @throws IOException if one of the txt records contains improperly formatted JSON.\n   */\n  @VisibleForTesting\n  static List<Map<String, ?>> parseTxtResults(List<String> txtRecords) throws IOException {\n    List<Map<String, ?>> possibleServiceConfigChoices = new ArrayList<>();\n    for (String txtRecord : txtRecords) {\n      if (!txtRecord.startsWith(SERVICE_CONFIG_PREFIX)) {\n        logger.log(Level.FINE, \"Ignoring non service config {0}\", new Object[]{txtRecord});\n        continue;\n      }\n      Object rawChoices = JsonParser.parse(txtRecord.substring(SERVICE_CONFIG_PREFIX.length()));\n      if (!(rawChoices instanceof List)) {\n        throw new ClassCastException(\"wrong type \" + rawChoices);\n      }\n      List<?> listChoices = (List<?>) rawChoices;\n      possibleServiceConfigChoices.addAll(JsonUtil.checkObjectList(listChoices));\n    }\n    return possibleServiceConfigChoices;\n  }\n\n  @Nullable\n  private static final Double getPercentageFromChoice(Map<String, ?> serviceConfigChoice) {\n    return JsonUtil.getNumberAsDouble(serviceConfigChoice, SERVICE_CONFIG_CHOICE_PERCENTAGE_KEY);\n  }\n\n  @Nullable\n  private static final List<String> getClientLanguagesFromChoice(\n      Map<String, ?> serviceConfigChoice) {\n    return JsonUtil.getListOfStrings(\n        serviceConfigChoice, SERVICE_CONFIG_CHOICE_CLIENT_LANGUAGE_KEY);\n  }","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/core/src/main/java/io/grpc/internal/DnsNameResolver.java#L388-L424","documentation":"DnsNameResolver parses gRPC service-config choices from DNS TXT records: each `grpc_config=` TXT record must be JSON whose top level is a list. If the parsed JSON is not a List (e.g. an object or scalar), parseTxtResults throws ClassCastException(\"wrong type ...\") because the record cannot be interpreted as a list of service-config choices.","triggerScenarios":"A DNS TXT record starting with the gRPC service-config prefix whose JSON value is not an array, e.g. `grpc_config={...}` (object) or `grpc_config=3`, encountered during resolution of the hostname.","commonSituations":"Misconfigured DNS records published by infrastructure teams; hand-edited TXT entries; service meshes emitting the wrong service-config schema; stale records left over from a config format change.","solutions":["Fix the DNS TXT record so the value after the `grpc_config=` prefix is a JSON array of service-config choice objects.","Validate each TXT record with a JSON linter (top level must be `[...]`) before publishing it.","If multiple TXT records exist, remove the malformed one or set it to a non-`grpc_config` prefix so it is ignored."],"exampleFix":"// before (TXT record)\ngrpc_config={\"serviceConfig\":{...}}\n// after (TXT record)\ngrpc_config=[{\"serviceConfig\":{...}}]","handlingStrategy":"validation","validationCode":"Object parsed = JsonParser.parse(txtRecord.substring(prefix.length()));\nif (!(parsed instanceof List)) throw new IllegalArgumentException(\"grpc_config TXT must be a JSON array\");","typeGuard":"boolean isJsonArray(Object o) { return o instanceof List; }","tryCatchPattern":"try {\n  resolver.resolve(target);\n} catch (ClassCastException e) {\n  // fall back to default service config / retry resolution\n}","preventionTips":["Lint DNS TXT grpc_config records: top level must be a JSON array.","Use automation with schema validation to publish service-config records.","Purge stale or hand-edited TXT records."],"tags":["grpc","dns","service-config","json"],"backgroundTag":"type-mismatch","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"}