{"record":{"id":"1efd225ba78de362","repo":"apache/rocketmq","slug":"message-queues-can-not-be-null-or-empty","errorCode":null,"errorMessage":"Message queues can not be null or empty.","messagePattern":"Message queues can not be null or empty\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultLitePullConsumerImpl.java","lineNumber":578,"sourceCode":"            assignedMessageQueue.setRebalanceImpl(this.rebalanceImpl);\n            if (serviceState == ServiceState.RUNNING) {\n                this.mQClientFactory.sendHeartbeatToAllBrokerWithLock();\n                updateTopicSubscribeInfoWhenSubscriptionChanged();\n            }\n        } catch (Exception e) {\n            throw new MQClientException(\"subscribe exception\", e);\n        }\n    }\n\n    public synchronized void unsubscribe(final String topic) {\n        this.rebalanceImpl.getSubscriptionInner().remove(topic);\n        removePullTaskCallback(topic);\n        assignedMessageQueue.removeAssignedMessageQueue(topic);\n    }\n\n    public synchronized void assign(Collection<MessageQueue> messageQueues) {\n        if (messageQueues == null || messageQueues.isEmpty()) {\n            throw new IllegalArgumentException(\"Message queues can not be null or empty.\");\n        }\n        setSubscriptionType(SubscriptionType.ASSIGN);\n        assignedMessageQueue.updateAssignedMessageQueue(messageQueues);\n        if (serviceState == ServiceState.RUNNING) {\n            updateAssignPullTask(messageQueues);\n        }\n    }\n\n    public synchronized void setSubExpressionForAssign(final String topic, final String subExpression) {\n        if (StringUtils.isBlank(subExpression)) {\n            throw new IllegalArgumentException(\"subExpression can not be null or empty.\");\n        }\n        if (serviceState != ServiceState.CREATE_JUST) {\n            throw new IllegalStateException(\"setAssignTag only can be called before start.\");\n        }\n        setSubscriptionType(SubscriptionType.ASSIGN);\n        topicToSubExpression.put(topic, subExpression);\n    }","sourceCodeStart":560,"sourceCodeEnd":596,"githubUrl":"https://github.com/apache/rocketmq/blob/293f5885719fc4aa3619446a1900f58ccfcfdd29/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultLitePullConsumerImpl.java#L560-L596","documentation":"DefaultLitePullConsumerImpl.assign(Collection<MessageQueue>) throws this IllegalArgumentException when the passed collection is null or empty. In ASSIGN mode the consumer pulls exclusively from the queues you explicitly assign, so an empty assignment leaves it nothing to consume and is rejected outright.","triggerScenarios":"consumer.assign(null) or consumer.assign(Collections.emptyList()) on a DefaultLitePullConsumer; assigning a queue list filtered down to zero entries.","commonSituations":"Queue lists fetched from fetchMessageQueues(topic) then filtered by tags/fields until empty; race where the topic metadata returns no queues yet and assign is called with the empty result.","solutions":["Guard: only call assign when the collection is non-null and !isEmpty()","If the list came from fetchMessageQueues, wait/retry until topic route metadata returns queues","Fall back to subscribe() mode if dynamic queue discovery is what you actually need"],"exampleFix":"// before\nconsumer.assign(queues.stream().filter(q -> q.getBrokerName().equals(broker)).collect(Collectors.toList()));\n\n// after\nList<MessageQueue> selected = queues.stream().filter(q -> q.getBrokerName().equals(broker)).collect(Collectors.toList());\nif (!selected.isEmpty()) consumer.assign(selected); else throw new IllegalStateException(\"no queues for broker \" + broker);","handlingStrategy":"validation","validationCode":"if (messageQueues != null && !messageQueues.isEmpty()) {\n    consumer.assign(messageQueues);\n} else {\n    throw new IllegalStateException(\"queue list empty — check topic route metadata\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass a filtered collection straight to assign() — check size first","If queues come from fetchMessageQueues, handle the empty result explicitly"],"tags":["rocketmq","consumer","assign","validation"],"backgroundTag":null,"analyzedSha":"293f5885719fc4aa3619446a1900f58ccfcfdd29","analyzedAt":"2026-08-14T11:50:13.822Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}