{"record":{"id":"9e7be501d098e35b","repo":"apache/rocketmq","slug":"allocatemessagequeuestrategy-is-null-9e7be5","errorCode":null,"errorMessage":"allocateMessageQueueStrategy is null","messagePattern":"allocateMessageQueueStrategy is null","errorType":"validation","errorClass":"MQClientException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPushConsumerImpl.java","lineNumber":1068,"sourceCode":"\n        if (null == this.defaultMQPushConsumer.getConsumeFromWhere()) {\n            throw new MQClientException(\n                \"consumeFromWhere is null\"\n                    + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL),\n                null);\n        }\n\n        Date dt = UtilAll.parseDate(this.defaultMQPushConsumer.getConsumeTimestamp(), UtilAll.YYYYMMDDHHMMSS);\n        if (null == dt) {\n            throw new MQClientException(\n                \"consumeTimestamp is invalid, the valid format is yyyyMMddHHmmss,but received \"\n                    + this.defaultMQPushConsumer.getConsumeTimestamp()\n                    + \" \" + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null);\n        }\n\n        // allocateMessageQueueStrategy\n        if (null == this.defaultMQPushConsumer.getAllocateMessageQueueStrategy()) {\n            throw new MQClientException(\n                \"allocateMessageQueueStrategy is null\"\n                    + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL),\n                null);\n        }\n\n        // subscription\n        if (null == this.defaultMQPushConsumer.getSubscription()) {\n            throw new MQClientException(\n                \"subscription is null\"\n                    + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL),\n                null);\n        }\n\n        // messageListener\n        if (null == this.defaultMQPushConsumer.getMessageListener()) {\n            throw new MQClientException(\n                \"messageListener is null\"\n                    + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL),","sourceCodeStart":1050,"sourceCodeEnd":1086,"githubUrl":"https://github.com/apache/rocketmq/blob/293f5885719fc4aa3619446a1900f58ccfcfdd29/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPushConsumerImpl.java#L1050-L1086","documentation":"checkConfig() requires an AllocateMessageQueueStrategy — the algorithm that splits queues among consumer instances in a group (e.g. AllocateMessageQueueAveragely). The field defaults to a valid strategy, so null means it was explicitly cleared or bypassed via reflection/mocking.","triggerScenarios":"Calling setAllocateMessageQueueStrategy(null); constructing the impl object directly in tests with mocks that return null from the getter.","commonSituations":"Unit tests mocking DefaultMQPushConsumer; config copy code that assigns every field including nulls; custom strategy injection where the custom bean failed to initialize and null was passed.","solutions":["Do not set the strategy to null; omit the setter call to keep the default AllocateMessageQueueAveragely","If injecting a custom strategy, ensure the bean is non-null before assignment and fail fast otherwise","In tests, build a real DefaultMQPushConsumer rather than a partial mock"],"exampleFix":"// before\nconsumer.setAllocateMessageQueueStrategy(null);\n\n// after\n// omit the call entirely (default), or:\nconsumer.setAllocateMessageQueueStrategy(new AllocateMessageQueueAveragely());","handlingStrategy":"validation","validationCode":"AllocateMessageQueueStrategy s = strategy != null ? strategy : new AllocateMessageQueueAveragely();\nconsumer.setAllocateMessageQueueStrategy(s);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call setAllocateMessageQueueStrategy(null); omit the call for defaults","Verify custom strategy beans are non-null before wiring them in DI"],"tags":["rocketmq","config","rebalance","validation"],"backgroundTag":null,"analyzedSha":"293f5885719fc4aa3619446a1900f58ccfcfdd29","analyzedAt":"2026-08-14T11:50:13.822Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}