{"record":{"id":"a214142448465db3","repo":"apache/rocketmq","slug":"topic-is-null-a21414","errorCode":null,"errorMessage":"topic is null","messagePattern":"topic is null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java","lineNumber":123,"sourceCode":"\n    private void isRunning() throws MQClientException {\n        if (this.serviceState != ServiceState.RUNNING) {\n            throw new MQClientException(\"The consumer is not in running status, \"\n                + this.serviceState\n                + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK),\n                null);\n        }\n    }\n\n    public long fetchConsumeOffset(MessageQueue mq, boolean fromStore) throws MQClientException {\n        this.isRunning();\n        return this.offsetStore.readOffset(mq, fromStore ? ReadOffsetType.READ_FROM_STORE : ReadOffsetType.MEMORY_FIRST_THEN_STORE);\n    }\n\n    public Set<MessageQueue> fetchMessageQueuesInBalance(String topic) throws MQClientException {\n        this.isRunning();\n        if (null == topic) {\n            throw new IllegalArgumentException(\"topic is null\");\n        }\n\n        ConcurrentMap<MessageQueue, ProcessQueue> mqTable = this.rebalanceImpl.getProcessQueueTable();\n        Set<MessageQueue> mqResult = new HashSet<>();\n        for (MessageQueue mq : mqTable.keySet()) {\n            if (mq.getTopic().equals(topic)) {\n                mqResult.add(mq);\n            }\n        }\n\n        return parseSubscribeMessageQueues(mqResult);\n    }\n\n    public List<MessageQueue> fetchPublishMessageQueues(String topic) throws MQClientException {\n        this.isRunning();\n        return this.mQClientFactory.getMQAdminImpl().fetchPublishMessageQueues(topic);\n    }\n","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/apache/rocketmq/blob/293f5885719fc4aa3619446a1900f58ccfcfdd29/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java#L105-L141","documentation":"DefaultMQPullConsumerImpl.fetchMessageQueuesInBalance(String topic) throws IllegalArgumentException(\"topic is null\") when topic is null. The method scans the rebalance processQueueTable for queues of that topic, so a null topic cannot match anything and is rejected after the isRunning() check.","triggerScenarios":"consumer.fetchMessageQueuesInBalance(null) on a started DefaultMQPullConsumer.","commonSituations":"Topic passed through several layers of code and lost; conditional assignment left the variable null.","solutions":["Validate topic != null before the call","Centralize topic constants in one enum/constants class to avoid null propagation"],"exampleFix":"// before\nSet<MessageQueue> qs = consumer.fetchMessageQueuesInBalance(topic);\n\n// after\nObjects.requireNonNull(topic, \"topic\");\nSet<MessageQueue> qs = consumer.fetchMessageQueuesInBalance(topic);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(topic, \"topic must not be null\");\nSet<MessageQueue> qs = consumer.fetchMessageQueuesInBalance(topic);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Centralize topic strings in constants/enums","Use Objects.requireNonNull at the boundary where topics enter your code"],"tags":["rocketmq","consumer","validation","argument"],"backgroundTag":null,"analyzedSha":"293f5885719fc4aa3619446a1900f58ccfcfdd29","analyzedAt":"2026-08-14T11:50:13.822Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}