{"record":{"id":"8c135623147e7e05","repo":"apache/rocketmq","slug":"machineroomresolver-is-null","errorCode":null,"errorMessage":"machineRoomResolver is null","messagePattern":"machineRoomResolver is null","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMachineRoomNearby.java","lineNumber":48,"sourceCode":" * 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        }\n\n        //group mq by machine room\n        Map<String/*machine room */, List<MessageQueue>> mr2Mq = new TreeMap<>();\n        for (MessageQueue mq : mqAll) {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/apache/rocketmq/blob/293f5885719fc4aa3619446a1900f58ccfcfdd29/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMachineRoomNearby.java#L30-L66","documentation":"Second constructor guard in AllocateMachineRoomNearby: the MachineRoomResolver (used to map consumers and queues to machine rooms) must not be null. Without it the strategy cannot group participants, so the constructor throws NullPointerException as a fail-fast contract violation.","triggerScenarios":"new AllocateMachineRoomNearby(strategy, null) — resolver omitted because the app has no machine-room awareness, or the resolver bean failed to construct.","commonSituations":"Copy-pasting the constructor call without implementing the MachineRoomResolver interface; DI setups where the resolver is an inner/anonymous bean that was never defined.","solutions":["Implement MachineRoomResolver (return a fixed room name for single-room deployments) and pass it","If you do not need machine-room logic, drop AllocateMachineRoomNearby and use AllocateMessageQueueAveragely directly","Verify DI wiring provides both constructor arguments"],"exampleFix":"// before\nnew AllocateMachineRoomNearby(new AllocateMessageQueueAveragely(), null);\n\n// after\nnew AllocateMachineRoomNearby(new AllocateMessageQueueAveragely(),\n    new MachineRoomResolver() {\n        public String brokerDeployIn(MessageQueue mq) { return \"DefaultRoom\"; }\n        public String consumerDeployIn(String clientIp) { return \"DefaultRoom\"; }\n    });","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(resolver, \"machineRoomResolver is null\");\nObjects.requireNonNull(delegate, \"allocateMessageQueueStrategy is null\");\nnew AllocateMachineRoomNearby(delegate, resolver);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Implement a fixed-room MachineRoomResolver for single-room deployments","Skip this strategy entirely if machine-room awareness is not needed"],"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"}