Skip to content

[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
apache:developfrom
zjncs:fix/query-assignment-null-body-fields
Open

[ISSUE #B5] Reject query assignment requests with missing required body fields instead of failing with NPE#11097
zjncs wants to merge 1 commit into
apache:developfrom
zjncs:fix/query-assignment-null-body-fields

Conversation

@zjncs

@zjncs zjncs commented Sep 9, 2026

Copy link
Copy Markdown

Motivation

QUERY_ASSIGNMENT and SET_MESSAGE_REQUEST_MODE requests whose body is missing topic, consumerGroup or messageModel (e.g. sent by an old/foreign client or a hand-crafted request — the JSON body simply leaves the field unset) currently fail deep inside QueryAssignmentProcessor with a NullPointerException instead of a proper error response:

  • getMessageRequestMode(null, ...) / findSubscriptionGroupConfig(null) / getConsumerGroupInfo(null)ConcurrentHashMap.get(null) throws NPE (Object.hashCode() ... because "key" is null);
  • doLoadBalance does switch (messageModel) → NPE on the null enum (MessageModel.ordinal() ... is null) — the messageModel field has no default in QueryAssignmentRequestBody;
  • setMessageRequestMode calls topic.startsWith(...) on a null topic → NPE.

The client only receives an opaque SYSTEM_ERROR carrying the NPE stack. Guarding the required body fields up front and answering INVALID_PARAMETER matches how other processors (e.g. AdminBrokerProcessor, PollingInfoProcessor) respond to malformed requests.

Modifications

  • queryAssignment: reject with INVALID_PARAMETER when topic/consumerGroup is empty or messageModel is null, before any table lookup or doLoadBalance.
  • setMessageRequestMode: reject with INVALID_PARAMETER when topic/consumerGroup is 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.:

testQueryAssignmentWithNullTopic » NullPointer  Cannot invoke "Object.hashCode()" because "key" is null
testQueryAssignmentWithNullMessageModel » NullPointer  Cannot invoke "MessageModel.ordinal()" because "messageModel" is null
testSetMessageRequestModeWithNullTopic » NullPointer  Cannot invoke "String.startsWith(String)" because "topic" is null

Pass-after — full QueryAssignmentProcessorTest (5 existing + 5 new tests) is green:

mvn -pl broker test -Dtest='QueryAssignmentProcessorTest'
Tests run: 10, Failures: 0, Errors: 0, Skipped: 0

…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>
Copilot AI lite review requested due to automatic review settings September 9, 2026 10:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants