Before Creating the Bug Report
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
- Create a PullAPIWrapper.
- Enable class filter in the pull sys flag.
- 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.
- Call PullAPIWrapper#pullKernelImpl.
- 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.
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#computePullFromWhichFilterServermay throw aNullPointerExceptionif the local topic route table does not contain route data for the target topic.The current code directly dereferences
topicRouteData: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
What Did You Expect to See?
The client should fail gracefully with MQClientException, for example:
Find Filter Server Failed, Broker Addr: xxx topic: xxxThis 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#computePullFromWhichFilterServerThe 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.