Skip to content

[Bug] PullAPIWrapper throws NPE when class filter topic route data is missing #10419

@yin-bo-Final

Description

@yin-bo-Final

Before Creating the Bug Report

  • I found a bug, not just asking a question, which should be created in GitHub Discussions.

  • I have searched the GitHub Issues and GitHub Discussions of this repository and believe that this is not a duplicate.

  • I have confirmed that this bug belongs to the current repository, not other repositories of RocketMQ.

Runtime platform environment

ubuntu

RocketMQ version

develop branch / rocketmq-all-5.5.0

JDK Version

JDK 8

Describe the Bug

When a consumer pulls messages with class filter enabled, PullAPIWrapper#computePullFromWhichFilterServer may throw a NullPointerException if the local topic route table does not contain route data for the target topic.

The current code directly dereferences topicRouteData:

TopicRouteData topicRouteData = topicRouteTable.get(topic);
List<String> list = topicRouteData.getFilterServerTable().get(brokerAddr);

If topicRouteData is null, the client throws NPE before reaching the existing business error path.

The method already has a clear fallback exception when no filter server can be found:

throw new MQClientException("Find Filter Server Failed, Broker Addr: " + brokerAddr + " topic: " + topic, null);
So the client should fail with MQClientException instead of exposing a raw NPE.

Steps to Reproduce

  1. Create a PullAPIWrapper.
  2. Enable class filter in the pull sys flag.
  3. Mock or configure MQClientInstance#getTopicRouteTable() to return a route table that does not contain the target topic, or contains a TopicRouteData without a filter server mapping for the broker address.
  4. Call PullAPIWrapper#pullKernelImpl.
  5. The call enters computePullFromWhichFilterServer and throws NullPointerException.

What Did You Expect to See?

The client should fail gracefully with MQClientException, for example: Find Filter Server Failed, Broker Addr: xxx topic: xxx
This is consistent with the existing method behavior when no filter server is found.

What Did You See Instead?

The client may throw NullPointerException from PullAPIWrapper#computePullFromWhichFilterServer before reaching the intended MQClientException branch.

Additional Context

This problem is caused by method:
org.apache.rocketmq.client.impl.consumer.PullAPIWrapper#computePullFromWhichFilterServer
The method currently assumes that topicRouteData is always available before accessing its filter server table. When the route data is missing, it may be better to fall through to the existing MQClientException path instead of throwing NPE.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions