apache / apache/rocketmq

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

Open Beginner friendly
#10,873 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
22.6k
Forks
12k
Avg merge
3d 1h
Merged PRs (30d)
27

Description

### Before Creating the Bug Report

- [x] I found a bug, not just a question.
- [x] I searched open GitHub Issues and pull requests and found no duplicate.
- [x] I confirmed that this bug belongs to Apache RocketMQ.

### Runtime platform environment

macOS (Darwin), reproduced with an isolated local unit test.

### RocketMQ version

Branch: develop
Git commit: fd0c95920e0deac96ce2ae27442747cc5e65e930

### JDK Version

Zulu OpenJDK 8 (8.94.0.17)

### Describe the Bug

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

### Steps to Reproduce

1. Create a default BrokerData and call selectBrokerAddr.
2. Alternatively, set brokerAddrs to an empty HashMap and call selectBrokerAddr.
3. Observe the exception.

### What Did You Expect to See?

The method should return null when no broker address is registered, consistent with its nullable selection result.

### What Did You See Instead?

The method throws for both null and empty address tables.

### Additional Context

Master preference and slave fallback remain valid; only the no-address boundary is affected.

Contributor guide

Open the contributing guide

Research direction

Start at BrokerData.selectBrokerAddr and reproduce the issue with a default BrokerData and an empty brokerAddrs map using an isolated local unit test. Add regression coverage for both no-address cases, while confirming master preference and slave fallback remain unchanged. Done means no registered address returns null instead of throwing.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
distributed-systems
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.