[Bug] LitePullConsumerAssign example throws IndexOutOfBoundsException for a topic with a single queue
Author: chennaji9Created Sep 30, 2026Updated Sep 30, 2026
Description
The lite-pull assign example example/src/main/java/org/apache/rocketmq/example/simple/LitePullConsumerAssign.java crashes for topics with a single message queue:
Collection<MessageQueue> mqSet = litePullConsumer.fetchMessageQueues("TopicTest");
List<MessageQueue> list = new ArrayList<>(mqSet);
List<MessageQueue> assignList = new ArrayList<>();
for (int i = 0; i < list.size() / 2; i++) {
assignList.add(list.get(i));
}
litePullConsumer.assign(assignList);
litePullConsumer.seek(assignList.get(0), 10);list.size() / 2 is integer division. With 1 queue the loop body never executes, assignList stays empty, and assignList.get(0) throws IndexOutOfBoundsException. A single-queue topic is a perfectly legal setup (fresh topics, small test clusters), so the example is unusable there. (With 3 queues it also assigns only 1 queue — arguably not "half" either.)
Expected behavior
The example should assign at least one queue whenever the topic has queues — e.g. use ceiling division (list.size() + 1) / 2 so 1 queue → 1 assigned, 3 → 2, 4 → 2 — instead of crashing on assignList.get(0).
Source: apache/rocketmq