{"record":{"id":"42b39e17a94420d7","repo":"grpc/grpc-java","slug":"invalid-message-type-unpackedmessage-getclass","errorCode":null,"errorMessage":"Invalid message type: \" + unpackedMessage.getClass()","messagePattern":"Invalid message type: \" \\+ unpackedMessage\\.getClass\\(\\)","errorType":"validation","errorClass":"ResourceInvalidException","httpStatus":null,"severity":"error","filePath":"xds/src/main/java/io/grpc/xds/XdsClusterResource.java","lineNumber":129,"sourceCode":"  public boolean shouldRetrieveResourceKeysForArgs() {\n    return true;\n  }\n\n  @Override\n  protected boolean isFullStateOfTheWorld() {\n    return true;\n  }\n\n  @Override\n  @SuppressWarnings(\"unchecked\")\n  protected Class<Cluster> unpackedClassName() {\n    return Cluster.class;\n  }\n\n  @Override\n  protected CdsUpdate doParse(Args args, Message unpackedMessage) throws ResourceInvalidException {\n    if (!(unpackedMessage instanceof Cluster)) {\n      throw new ResourceInvalidException(\"Invalid message type: \" + unpackedMessage.getClass());\n    }\n    Set<String> certProviderInstances = null;\n    if (args.getBootstrapInfo() != null && args.getBootstrapInfo().certProviders() != null) {\n      certProviderInstances = args.getBootstrapInfo().certProviders().keySet();\n    }\n    return processCluster((Cluster) unpackedMessage, certProviderInstances,\n        args.getServerInfo(), loadBalancerRegistry);\n  }\n\n  @VisibleForTesting\n  static CdsUpdate processCluster(Cluster cluster,\n                                  Set<String> certProviderInstances,\n                                  ServerInfo serverInfo,\n                                  LoadBalancerRegistry loadBalancerRegistry)\n      throws ResourceInvalidException {\n    StructOrError<CdsUpdate.Builder> structOrError;\n    switch (cluster.getClusterDiscoveryTypeCase()) {\n      case TYPE:","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/xds/src/main/java/io/grpc/xds/XdsClusterResource.java#L111-L147","documentation":"XdsClusterResource.doParse expects the unpacked Any message from the xDS response to be an envoy Cluster proto. If the unpacked message is any other type, the resource payload does not correspond to a CDS resource and a ResourceInvalidException naming the actual class is thrown.","triggerScenarios":"An xDS management server sends a CDS resource whose type_url does not match the payload (e.g. a Listener or RouteConfiguration packed under the cluster resource URL), or a custom/buggy server packs the wrong message.","commonSituations":"Misconfigured management server resource type mappings; proxy servers (e.g. some Envoy forks or gRPC server impls) with protocol bugs; tests feeding hand-built Any protos with the wrong type_url.","solutions":["Verify the management server returns Cluster protos under the CDS type_url (type.googleapis.com/envoy.config.cluster.v3.Cluster)","Fix the resource-type-to-message mapping on the xDS server side","Upgrade the xDS control plane / grpc-java to compatible versions"],"exampleFix":"// before\nAny.newBuilder().setTypeUrl(\"type.googleapis.com/envoy.config.listener.v3.Listener\").setPayload(clusterBytes)\n// after\nAny.newBuilder().setTypeUrl(\"type.googleapis.com/envoy.config.cluster.v3.Cluster\").setPayload(clusterBytes)","handlingStrategy":"type-guard","validationCode":"if (!\"type.googleapis.com/envoy.config.cluster.v3.Cluster\".equals(any.getTypeUrl())) {\n  throw new ResourceInvalidException(\"Unexpected type_url for CDS resource: \" + any.getTypeUrl());\n}","typeGuard":"boolean isClusterResource(Any any) {\n  return any.getTypeUrl().endsWith(\"envoy.config.cluster.v3.Cluster\");\n}","tryCatchPattern":"try {\n  cdsUpdate = xdsClusterResource.parseResource(args);\n} catch (ResourceInvalidException e) {\n  logger.atWarning().log(\"Invalid CDS resource: %s\", e.getMessage());\n  return Status.INVALID_ARGUMENT.withDescription(e.getMessage()).asException();\n}","preventionTips":["Verify management server maps CDS type_url to Cluster protos","Check server-side resource serialization in mixed-version deployments","Add type_url assertions in xDS integration tests"],"tags":["grpc","xds","cds","protobuf"],"backgroundTag":"type-mismatch","analyzedSha":"64daddc1f3d1975670f769f3e97bde8b2ba32d25","analyzedAt":"2026-09-08T06:14:57.704Z","contentChangedAt":"2026-09-08T06:14:57.704Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}