{"record":{"id":"eae08950ec650001","repo":"apache/rocketmq","slug":"allocatemessagequeuestrategy-is-null","errorCode":null,"errorMessage":"allocateMessageQueueStrategy is null","messagePattern":"allocateMessageQueueStrategy is null","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMachineRoomNearby.java","lineNumber":44,"sourceCode":"import org.apache.rocketmq.common.message.MessageQueue;\n\n/**\n * An allocate strategy proxy for based on machine room nearside priority. An actual allocate strategy can be\n * specified.\n *\n * If any consumer is alive in a machine room, the message queue of the broker which is deployed in the same machine\n * should only be allocated to those. Otherwise, those message queues can be shared along all consumers since there are\n * no alive consumer to monopolize them.\n */\npublic class AllocateMachineRoomNearby extends AbstractAllocateMessageQueueStrategy {\n\n    private final AllocateMessageQueueStrategy allocateMessageQueueStrategy;//actual allocate strategy\n    private final MachineRoomResolver machineRoomResolver;\n\n    public AllocateMachineRoomNearby(AllocateMessageQueueStrategy allocateMessageQueueStrategy,\n        MachineRoomResolver machineRoomResolver) throws NullPointerException {\n        if (allocateMessageQueueStrategy == null) {\n            throw new NullPointerException(\"allocateMessageQueueStrategy is null\");\n        }\n\n        if (machineRoomResolver == null) {\n            throw new NullPointerException(\"machineRoomResolver is null\");\n        }\n\n        this.allocateMessageQueueStrategy = allocateMessageQueueStrategy;\n        this.machineRoomResolver = machineRoomResolver;\n    }\n\n    @Override\n    public List<MessageQueue> allocate(String consumerGroup, String currentCID, List<MessageQueue> mqAll,\n        List<String> cidAll) {\n\n        List<MessageQueue> result = new ArrayList<>();\n        if (!check(consumerGroup, currentCID, mqAll, cidAll)) {\n            return result;\n        }","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/apache/rocketmq/blob/293f5885719fc4aa3619446a1900f58ccfcfdd29/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMachineRoomNearby.java#L26-L62","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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()"],"exampleFix":"// before\nnew AllocateMachineRoomNearby(null, resolver);\n\n// after\nnew AllocateMachineRoomNearby(new AllocateMessageQueueAveragely(), resolver);","handlingStrategy":"validation","validationCode":"AllocateMessageQueueStrategy inner =\n    (delegate != null) ? delegate : new AllocateMessageQueueAveragely();\nnew AllocateMachineRoomNearby(inner, resolver);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Assert non-null constructor args in a small factory method","Verify DI wiring with a startup smoke test that instantiates the strategy"],"tags":["rebalance","allocation","null-check","constructor"],"backgroundTag":null,"analyzedSha":"293f5885719fc4aa3619446a1900f58ccfcfdd29","analyzedAt":"2026-08-14T11:50:13.822Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}