{"record":{"id":"278dfea34b053553","repo":"apache/rocketmq","slug":"subscription-is-null-278dfe","errorCode":null,"errorMessage":"subscription is null","messagePattern":"subscription is null","errorType":"validation","errorClass":"MQClientException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPushConsumerImpl.java","lineNumber":1076,"sourceCode":"        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),\n                null);\n        }\n\n        boolean orderly = this.defaultMQPushConsumer.getMessageListener() instanceof MessageListenerOrderly;\n        boolean concurrently = this.defaultMQPushConsumer.getMessageListener() instanceof MessageListenerConcurrently;\n        if (!orderly && !concurrently) {\n            throw new MQClientException(\n                \"messageListener must be instanceof MessageListenerOrderly or MessageListenerConcurrently\"","sourceCodeStart":1058,"sourceCodeEnd":1094,"githubUrl":"https://github.com/apache/rocketmq/blob/293f5885719fc4aa3619446a1900f58ccfcfdd29/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPushConsumerImpl.java#L1058-L1094","documentation":"checkConfig() requires the subscription map to be non-null. subscribe() populates it, so this fires when start() is called before any subscribe() — the consumer has nothing to consume and the client refuses to start with a null subscription table.","triggerScenarios":"Calling consumer.start() without ever calling consumer.subscribe(topic, subExpression); code that clears subscriptions (getSubscription().clear()) before start; conditional subscription logic that skips all subscribe calls on some path.","commonSituations":"Forgetting subscribe() in quick-start code; per-environment wiring where the topic list is empty in one environment so the subscribe loop never runs.","solutions":["Call consumer.subscribe(topic, \"*\") (or an SQL92/tag expression) before start()","If topics come from a list, fail loudly when the list is empty instead of starting with nothing","Keep subscribe-before-start ordering in your consumer factory method"],"exampleFix":"// before\nDefaultMQPushConsumer c = new DefaultMQPushConsumer(\"g\");\nc.setMessageListener(...);\nc.start(); // no subscribe() -> subscription is null\n\n// after\nc.subscribe(\"order-topic\", \"*\");\nc.setMessageListener(...);\nc.start();","handlingStrategy":"validation","validationCode":"if (topics == null || topics.isEmpty())\n    throw new IllegalArgumentException(\"At least one topic required\");\nfor (String t : topics) consumer.subscribe(t, \"*\");\nconsumer.start();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always subscribe before start in one factory method","Fail config load when the topic list is empty rather than starting a no-op consumer"],"tags":["rocketmq","config","subscription","validation"],"backgroundTag":null,"analyzedSha":"293f5885719fc4aa3619446a1900f58ccfcfdd29","analyzedAt":"2026-08-14T11:50:13.822Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}