apache/rocketmq · error · AuthorizationException

topic is null.

Error message

topic is null.

What it means

Thrown by the gRPC path newContext(Metadata, QueryRouteRequest): the topic Resource in a QueryRouteRequest has a blank name, so AuthorizationException('topic is null.') is raised. Before the broker can authorize route discovery, it must know which topic to authorize PUB/SUB on — both actions are attached to this single topic resource — so a nameless topic cannot proceed.

Source

Thrown at auth/src/main/java/org/apache/rocketmq/auth/authorization/builder/DefaultAuthorizationContextBuilder.java:733

                        }
                    }
                } finally {
                    field.setAccessible(false);
                }
            }
        }

        if (CollectionUtils.isEmpty(result) && resource != null) {
            result.add(DefaultAuthorizationContext.of(subject, resource, Arrays.asList(actions), sourceIp));
        }

        return result;
    }

    private List<DefaultAuthorizationContext> newContext(Metadata metadata, QueryRouteRequest request) {
        apache.rocketmq.v2.Resource topic = request.getTopic();
        if (StringUtils.isBlank(topic.getName())) {
            throw new AuthorizationException("topic is null.");
        }
        Subject subject = null;
        if (metadata.containsKey(GrpcConstants.AUTHORIZATION_AK)) {
            subject = User.of(metadata.get(GrpcConstants.AUTHORIZATION_AK));
        }
        Resource resource = Resource.ofTopic(topic.getName());
        String sourceIp = StringUtils.substringBeforeLast(metadata.get(GrpcConstants.REMOTE_ADDRESS), CommonConstants.COLON);
        DefaultAuthorizationContext context = DefaultAuthorizationContext.of(subject, resource, Arrays.asList(Action.PUB, Action.SUB), sourceIp);
        return Collections.singletonList(context);
    }

    private static List<DefaultAuthorizationContext> newContext(Metadata metadata, TelemetryCommand request) {
        if (request.getCommandCase() != TelemetryCommand.CommandCase.SETTINGS) {
            return null;
        }
        if (!request.getSettings().hasPublishing() && !request.getSettings().hasSubscription()) {
            throw new AclException("settings command doesn't have publishing or subscription.");
        }

View on GitHub (pinned to 293f588571)

Solutions

  1. Set topic.setName(topicName) on the QueryRouteRequest's Resource before sending, and validate the name is non-blank client-side.
  2. If the topic comes from config, fail fast at startup when it is blank rather than at route query time.
  3. Use the official rocketmq-client-java producer/consumer, which validates the topic before issuing QueryRoute.

Example fix

// before
Resource topic = Resource.newBuilder().build(); // name unset
QueryRouteRequest req = QueryRouteRequest.newBuilder().setTopic(topic).build();

// after
if (CharSequenceUtil.isBlank(topicName)) throw new IllegalArgumentException("topic required");
Resource topic = Resource.newBuilder().setName(topicName).build();
Defensive patterns

Strategy: validation

Validate before calling

if (topicName == null || topicName.isBlank()) {
    throw new IllegalArgumentException("topic name required for queryRoute");
}
QueryRouteRequest req = QueryRouteRequest.newBuilder()
    .setTopic(Resource.newBuilder().setName(topicName)).build();

Type guard

static boolean hasTopicName(apache.rocketmq.v2.Resource r) {
    return r != null && !r.getName().isBlank();
}

Prevention

When it happens

Trigger: A gRPC QueryRouteRequest where topic.name is unset, empty, or whitespace: client code building Resource.newBuilder() without setName, or copying a Resource proto with a missing name field. Note the null-check is only on getName() blankness, not on topic == null itself (calling request.getTopic() on an unset proto returns a default instance).

Common situations: New gRPC/protobuf clients forgetting setName on the topic resource; templating code that renders an empty topic string; topic names read from config that is missing in one environment; a shim layer mapping amqp/jms topic properties to the proto and dropping nulls to empty.

Related errors


AI-assisted analysis of apache/rocketmq@293f588571 (2026-08-14). Data as JSON: /api/errors/2959920504e4ae47. Report an issue: GitHub.