grpc/grpc-java · error · ResourceInvalidException

Invalid message type: ${unpackedMessage.getClass()}

Error message

Invalid message type: ${unpackedMessage.getClass()}

What it means

The RDS resource type parser expected the unpacked Any message to be an Envoy RouteConfiguration, but received a different message type. This is a type invariant check in doParse; it indicates the management server sent a resource whose packed message does not match the expected type_url for RDS.

Source

Thrown at xds/src/main/java/io/grpc/xds/XdsRouteConfigureResource.java:132

  public boolean shouldRetrieveResourceKeysForArgs() {
    return false;
  }

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

  @Override
  protected Class<RouteConfiguration> unpackedClassName() {
    return RouteConfiguration.class;
  }

  @Override
  protected RdsUpdate doParse(XdsResourceType.Args args, Message unpackedMessage)
      throws ResourceInvalidException {
    if (!(unpackedMessage instanceof RouteConfiguration)) {
      throw new ResourceInvalidException("Invalid message type: " + unpackedMessage.getClass());
    }
    return processRouteConfiguration(
        (RouteConfiguration) unpackedMessage, FilterRegistry.getDefaultRegistry(), args);
  }

  private static RdsUpdate processRouteConfiguration(
      RouteConfiguration routeConfig, FilterRegistry filterRegistry, XdsResourceType.Args args)
      throws ResourceInvalidException {
    return new RdsUpdate(extractVirtualHosts(routeConfig, filterRegistry, args));
  }

  static List<VirtualHost> extractVirtualHosts(
      RouteConfiguration routeConfig, FilterRegistry filterRegistry, XdsResourceType.Args args)
      throws ResourceInvalidException {
    Map<String, PluginConfig> pluginConfigMap = new HashMap<>();
    ImmutableSet.Builder<String> optionalPlugins = ImmutableSet.builder();

    if (enableRouteLookup) {

View on GitHub (pinned to 64daddc1f3)

Solutions

  1. Fix the management server to send RouteConfiguration protos for RDS resources with the correct type_url
  2. Verify the resource's Any.type_url matches envoy.config.route.v3.RouteConfiguration
  3. In tests, pass a RouteConfiguration message to the parser instead of another type

Example fix

// before
Any any = Any.pack(Listener.getDefaultInstance()); // wrong type
// after
Any any = Any.pack(RouteConfiguration.newBuilder()...build());
Defensive patterns

Strategy: type-guard

Validate before calling

// Before feeding to the parser, confirm the unpacked type
if (!(unpacked instanceof RouteConfiguration)) {
  throw new IllegalArgumentException("Expected RouteConfiguration, got "
      + unpacked.getClass());
}

Type guard

static boolean isRouteConfiguration(Message msg) {
  return msg instanceof RouteConfiguration;
}

Try / catch

try {
  RdsUpdate update = XdsRouteConfigureResource.parseRds(args, any);
} catch (ResourceInvalidException e) {
  log.error("Bad RDS resource payload: {}", e.getMessage());
}

Prevention

When it happens

Trigger: XdsRouteConfigureResource.doParse receiving an unpackedMessage that is not io.envoyproxy.envoy.config.route.v3.RouteConfiguration — e.g. a Listener, Cluster, or other Envoy proto sent under a route-configuration type_url.

Common situations: Misbehaving or buggy control plane sending resources under the wrong type_url; manually injecting protobufs in tests; mixing Envoy API versions where the unpacked type differs.

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/2fce5700401fb2a9. Report an issue: GitHub.