apache/rocketmq · error · NullPointerException
allocateMessageQueueStrategy is null
Error message
allocateMessageQueueStrategy is null
What it means
AllocateMachineRoomNearby's constructor requires a non-null delegate AllocateMessageQueueStrategy (the strategy it applies within each machine room after grouping consumers). Passing null throws NullPointerException immediately — a fail-fast constructor contract, since allocation cannot proceed without an inner strategy.
Source
Thrown at client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMachineRoomNearby.java:44
import org.apache.rocketmq.common.message.MessageQueue;
/**
* An allocate strategy proxy for based on machine room nearside priority. An actual allocate strategy can be
* specified.
*
* If any consumer is alive in a machine room, the message queue of the broker which is deployed in the same machine
* should only be allocated to those. Otherwise, those message queues can be shared along all consumers since there are
* no alive consumer to monopolize them.
*/
public class AllocateMachineRoomNearby extends AbstractAllocateMessageQueueStrategy {
private final AllocateMessageQueueStrategy allocateMessageQueueStrategy;//actual allocate strategy
private final MachineRoomResolver machineRoomResolver;
public AllocateMachineRoomNearby(AllocateMessageQueueStrategy allocateMessageQueueStrategy,
MachineRoomResolver machineRoomResolver) throws NullPointerException {
if (allocateMessageQueueStrategy == null) {
throw new NullPointerException("allocateMessageQueueStrategy is null");
}
if (machineRoomResolver == null) {
throw new NullPointerException("machineRoomResolver is null");
}
this.allocateMessageQueueStrategy = allocateMessageQueueStrategy;
this.machineRoomResolver = machineRoomResolver;
}
@Override
public List<MessageQueue> allocate(String consumerGroup, String currentCID, List<MessageQueue> mqAll,
List<String> cidAll) {
List<MessageQueue> result = new ArrayList<>();
if (!check(consumerGroup, currentCID, mqAll, cidAll)) {
return result;
}View on GitHub (pinned to 293f588571)
Solutions
- Supply a concrete inner strategy, e.g. new AllocateMessageQueueAveragely()
- If wiring via DI, verify the delegate bean exists and the reference resolves
- Default the delegate: strategy != null ? strategy : new AllocateMessageQueueAveragely()
Example fix
// before new AllocateMachineRoomNearby(null, resolver); // after new AllocateMachineRoomNearby(new AllocateMessageQueueAveragely(), resolver);
Defensive patterns
Strategy: validation
Validate before calling
AllocateMessageQueueStrategy inner =
(delegate != null) ? delegate : new AllocateMessageQueueAveragely();
new AllocateMachineRoomNearby(inner, resolver); Prevention
- Assert non-null constructor args in a small factory method
- Verify DI wiring with a startup smoke test that instantiates the strategy
When it happens
Trigger: new AllocateMachineRoomNearby(null, resolver) — typically when the delegate strategy is injected via DI/framework config and the bean is missing or the field name is mistyped.
Common situations: Spring/XML bean wiring where the inner strategy bean id does not match the reference; programmatic setup where the delegate is conditionally created and the branch returned null.
Related errors
- machineRoomResolver is null
- illegal virtualNodeCnt :%d
- user can not be null
- currentCID is empty
- mqAll is null or mqAll empty
AI-assisted analysis of apache/rocketmq@293f588571 (2026-08-14).
Data as JSON: /api/errors/eae08950ec650001.
Report an issue: GitHub.