[ISSUE #B5] Reject query assignment requests with missing required body fields instead of failing with NPE - #11097
Open
zjncs wants to merge 1 commit into
Open
Conversation
…dy fields instead of failing with NPE A QUERY_ASSIGNMENT or SET_MESSAGE_REQUEST_MODE request whose body lacks topic, consumerGroup or messageModel currently fails deep inside the processor: ConcurrentHashMap.get(null) in getMessageRequestMode, findSubscriptionGroupConfig or getConsumerGroupInfo, a null-enum switch in doLoadBalance, or topic.startsWith on a null topic. The client only gets an opaque SYSTEM_ERROR carrying an NPE stack. Validate the required body fields up front and answer INVALID_PARAMETER. Signed-off-by: zjncs <18910855655@163.com>
RockteMQ-AI
approved these changes
Sep 9, 2026
RockteMQ-AI
left a comment
Contributor
There was a problem hiding this comment.
Summary
Adds null checks for topic, consumerGroup, and messageModel in QUERY_ASSIGNMENT and SET_MESSAGE_REQUEST_MODE request handlers — returns a proper error response instead of an NPE when a malformed/incomplete request arrives. Consistent with the existing validation style in the codebase. Thorough test coverage (5 new tests).
LGTM.
Automated review by github-manager-bot
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.
Motivation
QUERY_ASSIGNMENTandSET_MESSAGE_REQUEST_MODErequests whose body is missingtopic,consumerGroupormessageModel(e.g. sent by an old/foreign client or a hand-crafted request — the JSON body simply leaves the field unset) currently fail deep insideQueryAssignmentProcessorwith aNullPointerExceptioninstead of a proper error response:getMessageRequestMode(null, ...)/findSubscriptionGroupConfig(null)/getConsumerGroupInfo(null)→ConcurrentHashMap.get(null)throws NPE (Object.hashCode() ... because "key" is null);doLoadBalancedoesswitch (messageModel)→ NPE on the null enum (MessageModel.ordinal() ... is null) — themessageModelfield has no default inQueryAssignmentRequestBody;setMessageRequestModecallstopic.startsWith(...)on a null topic → NPE.The client only receives an opaque
SYSTEM_ERRORcarrying the NPE stack. Guarding the required body fields up front and answeringINVALID_PARAMETERmatches how other processors (e.g.AdminBrokerProcessor,PollingInfoProcessor) respond to malformed requests.Modifications
queryAssignment: reject withINVALID_PARAMETERwhentopic/consumerGroupis empty ormessageModelis null, before any table lookup ordoLoadBalance.setMessageRequestMode: reject withINVALID_PARAMETERwhentopic/consumerGroupis empty, before the retry-topic check and the config lookups.Verification
Fail-before (each of the 5 new tests errors on unpatched code with the NPE described above), e.g.:
Pass-after — full
QueryAssignmentProcessorTest(5 existing + 5 new tests) is green: