daguimu opened a new issue, #10216:
URL: https://github.com/apache/rocketmq/issues/10216

   ### Before Creating the Bug Report
   
   - [x] I found a bug, not just asking a question, which should be created in 
[GitHub Discussions](https://github.com/apache/rocketmq/discussions).
   
   - [x] I have searched the [GitHub 
Issues](https://github.com/apache/rocketmq/issues) and [GitHub 
Discussions](https://github.com/apache/rocketmq/discussions)  of this 
repository and believe that this is not a duplicate.
   
   - [x] 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):**
   ```java
   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):**
   ```java
   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:
   ```java
   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()`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to