Skip to content

[Bug] Potential NPE in EscapeBridge when topicPublishInfo is null #10216

@daguimu

Description

@daguimu

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

All platforms

RocketMQ version

develop branch (latest)

JDK Version

JDK 8+

Describe the Bug

In EscapeBridge.java, the methods asyncPutMessage() and asyncRemotePutMessageToSpecificQueue() call tryToFindTopicPublishInfo() but do not check for a null return value before dereferencing the result.

Location 1 - asyncPutMessage() (line ~187-190):

final TopicPublishInfo topicPublishInfo = this.brokerController.getTopicRouteInfoManager().tryToFindTopicPublishInfo(messageExt.getTopic());
final String producerGroup = getProducerGroup(messageExt);
final MessageQueue mqSelected = topicPublishInfo.selectOneMessageQueue(); // NPE if topicPublishInfo is null

Location 2 - asyncRemotePutMessageToSpecificQueue() (line ~252-253):

final TopicPublishInfo topicPublishInfo = this.brokerController.getTopicRouteInfoManager().tryToFindTopicPublishInfo(messageExt.getTopic());
List<MessageQueue> mqs = topicPublishInfo.getMessageQueueList(); // NPE if topicPublishInfo is null

In contrast, the putMessageToRemoteBroker() method in the same class (line ~126-131) properly handles this:

if (null == topicPublishInfo || !topicPublishInfo.ok()) {
    LOG.warn("putMessageToRemoteBroker: no route info ...");
    return null;
}

Steps to Reproduce

When a slave broker acting as master attempts to escape a message for a topic whose route information is not yet available (e.g., during startup or after a nameserver disconnection), tryToFindTopicPublishInfo() returns null, leading to NPE.

What Did You Expect to See?

The methods should check for null topicPublishInfo and return an appropriate error result, consistent with putMessageToRemoteBroker().

What Did You See Instead?

NullPointerException when topicPublishInfo is null.

Additional Context

The fix should add null/validity checks for topicPublishInfo consistent with the existing pattern in putMessageToRemoteBroker().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions