grpc/grpc-java · error · ResourceInvalidException

Invalid message type: " + unpackedMessage.getClass()

Error message

Invalid message type: " + unpackedMessage.getClass()

What it means

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.

Source

Thrown at xds/src/main/java/io/grpc/xds/XdsClusterResource.java:129

  public boolean shouldRetrieveResourceKeysForArgs() {
    return true;
  }

  @Override
  protected boolean isFullStateOfTheWorld() {
    return true;
  }

  @Override
  @SuppressWarnings("unchecked")
  protected Class<Cluster> unpackedClassName() {
    return Cluster.class;
  }

  @Override
  protected CdsUpdate doParse(Args args, Message unpackedMessage) throws ResourceInvalidException {
    if (!(unpackedMessage instanceof Cluster)) {
      throw new ResourceInvalidException("Invalid message type: " + unpackedMessage.getClass());
    }
    Set<String> certProviderInstances = null;
    if (args.getBootstrapInfo() != null && args.getBootstrapInfo().certProviders() != null) {
      certProviderInstances = args.getBootstrapInfo().certProviders().keySet();
    }
    return processCluster((Cluster) unpackedMessage, certProviderInstances,
        args.getServerInfo(), loadBalancerRegistry);
  }

  @VisibleForTesting
  static CdsUpdate processCluster(Cluster cluster,
                                  Set<String> certProviderInstances,
                                  ServerInfo serverInfo,
                                  LoadBalancerRegistry loadBalancerRegistry)
      throws ResourceInvalidException {
    StructOrError<CdsUpdate.Builder> structOrError;
    switch (cluster.getClusterDiscoveryTypeCase()) {
      case TYPE:

View on GitHub (pinned to 64daddc1f3)

Solutions

  1. Verify the management server returns Cluster protos under the CDS type_url (type.googleapis.com/envoy.config.cluster.v3.Cluster)
  2. Fix the resource-type-to-message mapping on the xDS server side
  3. Upgrade the xDS control plane / grpc-java to compatible versions

Example fix

// before
Any.newBuilder().setTypeUrl("type.googleapis.com/envoy.config.listener.v3.Listener").setPayload(clusterBytes)
// after
Any.newBuilder().setTypeUrl("type.googleapis.com/envoy.config.cluster.v3.Cluster").setPayload(clusterBytes)
Defensive patterns

Strategy: type-guard

Validate before calling

if (!"type.googleapis.com/envoy.config.cluster.v3.Cluster".equals(any.getTypeUrl())) {
  throw new ResourceInvalidException("Unexpected type_url for CDS resource: " + any.getTypeUrl());
}

Type guard

boolean isClusterResource(Any any) {
  return any.getTypeUrl().endsWith("envoy.config.cluster.v3.Cluster");
}

Try / catch

try {
  cdsUpdate = xdsClusterResource.parseResource(args);
} catch (ResourceInvalidException e) {
  logger.atWarning().log("Invalid CDS resource: %s", e.getMessage());
  return Status.INVALID_ARGUMENT.withDescription(e.getMessage()).asException();
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of grpc/grpc-java@64daddc1f3 (2026-09-08). Data as JSON: /api/errors/42b39e17a94420d7. Report an issue: GitHub.