{"record":{"id":"81db9a9a25b60d1e","repo":"apache/rocketmq","slug":"mq-is-null-81db9a","errorCode":null,"errorMessage":"mq is null","messagePattern":"mq is null","errorType":"exception","errorClass":"MQClientException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java","lineNumber":204,"sourceCode":"        return this.pullSyncImpl(mq, subscriptionData, offset, maxNums, false, timeout);\n    }\n\n    public PullResult pull(MessageQueue mq, MessageSelector messageSelector, long offset, int maxNums)\n        throws MQClientException, RemotingException, MQBrokerException, InterruptedException {\n        return pull(mq, messageSelector, offset, maxNums, this.defaultMQPullConsumer.getConsumerPullTimeoutMillis());\n    }\n\n    public PullResult pull(MessageQueue mq, MessageSelector messageSelector, long offset, int maxNums, long timeout)\n        throws MQClientException, RemotingException, MQBrokerException, InterruptedException {\n        SubscriptionData subscriptionData = getSubscriptionData(mq, messageSelector);\n        return this.pullSyncImpl(mq, subscriptionData, offset, maxNums, false, timeout);\n    }\n\n    private SubscriptionData getSubscriptionData(MessageQueue mq, String subExpression)\n        throws MQClientException {\n\n        if (null == mq) {\n            throw new MQClientException(\"mq is null\", null);\n        }\n\n        try {\n            return FilterAPI.buildSubscriptionData(mq.getTopic(), subExpression);\n        } catch (Exception e) {\n            throw new MQClientException(\"parse subscription error\", e);\n        }\n    }\n\n    private SubscriptionData getSubscriptionData(MessageQueue mq, MessageSelector messageSelector)\n        throws MQClientException {\n\n        if (null == mq) {\n            throw new MQClientException(\"mq is null\", null);\n        }\n\n        try {\n            return FilterAPI.build(mq.getTopic(),","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/apache/rocketmq/blob/293f5885719fc4aa3619446a1900f58ccfcfdd29/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java#L186-L222","documentation":"DefaultMQPullConsumerImpl.getSubscriptionData (the string-expression overload used by pull(...)) throws MQClientException(\"mq is null\") when the MessageQueue argument is null. The subscription is built from mq.getTopic(), so a null queue cannot produce a subscription and the pull is aborted before any request is sent.","triggerScenarios":"consumer.pull(null, subExpression, offset, maxNums, timeout); passing a queue looked up from a Map/Set that returned null.","commonSituations":"Queue selected from fetchMessageQueues() result that is empty; queue variable from a failed deserialization of a stored offset entry.","solutions":["Null-check mq before pull; assert the queue collection is non-empty first","When iterating fetched queues, handle the empty-set case instead of indexing into it"],"exampleFix":"// before\nSet<MessageQueue> qs = consumer.fetchMessageQueues(topic);\nPullResult r = consumer.pull(qs.isEmpty() ? null : qs.iterator().next(), \"*\", 0, 1, 3000);\n\n// after\nSet<MessageQueue> qs = consumer.fetchMessageQueues(topic);\nif (qs.isEmpty()) throw new IllegalStateException(\"no queues for \" + topic);\nPullResult r = consumer.pull(qs.iterator().next(), \"*\", 0, 1, 3000);","handlingStrategy":"validation","validationCode":"if (mq == null) throw new IllegalArgumentException(\"queue not resolved for pull\");\nPullResult r = consumer.pull(mq, subExpr, offset, maxNums, timeout);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check fetchMessageQueues() result is non-empty before taking an element","Never substitute null for a missing queue in pull calls"],"tags":["rocketmq","consumer","pull","null-check"],"backgroundTag":null,"analyzedSha":"293f5885719fc4aa3619446a1900f58ccfcfdd29","analyzedAt":"2026-08-14T11:50:13.822Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}