Skip to content

[ISSUE #10873] Guard BrokerData.selectBrokerAddr against empty address table - #10920

Open
btlqql wants to merge 1 commit into
apache:developfrom
btlqql:btlqql/fix-brokerdata-select-addr
Open

[ISSUE #10873] Guard BrokerData.selectBrokerAddr against empty address table#10920
btlqql wants to merge 1 commit into
apache:developfrom
btlqql:btlqql/fix-brokerdata-select-addr

Conversation

@btlqql

@btlqql btlqql commented Aug 12, 2026

Copy link
Copy Markdown

What is the purpose of the change

Fix #10873.

BrokerData.selectBrokerAddr assumed brokerAddrs is non-null and non-empty. A default BrokerData instance threw NullPointerException, while an empty map reached Random.nextInt(0) and threw IllegalArgumentException.

Brief changelog

  • BrokerData.selectBrokerAddr: return null for a null or empty address table

How was this patch verified

  • Code review of the master/slave selection path
  • git diff --check clean

@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

This PR adds a null/empty check for brokerAddrs in BrokerData.selectBrokerAddr() before accessing the map. This prevents potential NullPointerException or unexpected behavior when the address table is empty.

LGTM. Simple defensive fix.

Note: This PR also includes changes from #10914-#10919. See the series overlap comment on those PRs.


Automated review by github-manager-bot

@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.

Review Summary

This PR adds a null/empty guard in BrokerData.selectBrokerAddr to prevent NPE when the address table is empty.

Findings

  • [Critical] BrokerData.java — Without this guard, calling selectBrokerAddr on a broker with no registered addresses would throw NPE or return incorrect results.
  • [Info] Returning null for empty address tables is the correct defensive behavior, allowing callers to handle the missing broker gracefully.

Overall

Good defensive fix. Prevents NPE in routing logic when broker addresses are not yet available or have been removed.


Automated review by RockteMQ-AI

@btlqql
btlqql force-pushed the btlqql/fix-brokerdata-select-addr branch from aac534b to 0753ba4 Compare August 13, 2026 05:59

@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.

LGTM. Trivial change, looks good.


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.

[Bug] BrokerData.selectBrokerAddr crashes for an empty address table

2 participants