[ISSUE #10216] Fix potential NPE in EscapeBridge when topicPublishInfo is null#10507
Merged
Merged
Conversation
…ishInfo is null In asyncPutMessage() and asyncRemotePutMessageToSpecificQueue(), the return value of tryToFindTopicPublishInfo() is dereferenced without a null check, causing NullPointerException when topic route information is unavailable (e.g., during startup or after nameserver disconnection). This commit adds null/validity checks consistent with the existing pattern in putMessageToRemoteBroker(), returning PUT_TO_REMOTE_BROKER_FAIL with a warning log instead of crashing with NPE. Co-authored-by: Cursor <cursoragent@cursor.com>
RongtongJin
approved these changes
Jun 15, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #10507 +/- ##
=============================================
- Coverage 49.03% 48.02% -1.02%
+ Complexity 13471 13322 -149
=============================================
Files 1375 1377 +2
Lines 100381 100715 +334
Branches 12965 13012 +47
=============================================
- Hits 49223 48368 -855
- Misses 45172 46395 +1223
+ Partials 5986 5952 -34 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
RockteMQ-AI
reviewed
Jun 15, 2026
RockteMQ-AI
left a comment
Contributor
There was a problem hiding this comment.
Review by github-manager-bot
Summary
Adds null checks for topicPublishInfo in EscapeBridge.asyncPutMessage() and asyncRemotePutMessageToSpecificQueue() to prevent NPE when topic route info is unavailable.
Findings
- [Info]
EscapeBridge.java:188-192— The null checknull == topicPublishInfo || !topicPublishInfo.ok()correctly handles both missing route info and invalid publish info. ReturningPUT_TO_REMOTE_BROKER_FAILwithretryTopic=trueallows the caller to retry, which is the right behavior. - [Info]
EscapeBridge.java:258-262— Same pattern applied consistently in the second method. Good.
Suggestions
- The existing code at line ~260 already checks
if (null == mqs || mqs.isEmpty())after this new check. With the new guard ensuringtopicPublishInfo.ok(), themqsnull check becomes partially redundant (sinceok()impliesmessageQueueListis non-empty). Consider whether the existing check can be simplified, or add a comment explaining both guards serve different purposes. - Consider adding a unit test that mocks
tryToFindTopicPublishInfo()returning null to verify the failover path.
Clean defensive fix. Fixes #10216. 👍
Automated review by github-manager-bot
ShannonDing
approved these changes
Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix NullPointerException in
EscapeBridgewhentryToFindTopicPublishInfo()returns null.Motivation
In
EscapeBridge.java, two methods dereference the result oftryToFindTopicPublishInfo()without null checks:asyncPutMessage()— callstopicPublishInfo.selectOneMessageQueue()directlyasyncRemotePutMessageToSpecificQueue()— callstopicPublishInfo.getMessageQueueList()directlyWhen 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), this causes NPE.
In contrast,
putMessageToRemoteBroker()in the same class already handles this correctly:Changes
null == topicPublishInfo || !topicPublishInfo.ok()) in both methodsPutMessageStatus.PUT_TO_REMOTE_BROKER_FAILwith a warning log, consistent with the existing patterntopicPublishInfois validTest Plan
mvn compile -pl broker -am)putMessageToRemoteBroker()in the same fileFixes #10216