{"record":{"id":"ac93b7f72f81ad7f","repo":"apache/rocketmq","slug":"illegal-virtualnodecnt-d","errorCode":null,"errorMessage":"illegal virtualNodeCnt :%d","messagePattern":"illegal virtualNodeCnt :(.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueConsistentHash.java","lineNumber":45,"sourceCode":"/**\n * Consistent Hashing queue algorithm\n */\npublic class AllocateMessageQueueConsistentHash extends AbstractAllocateMessageQueueStrategy {\n\n    private final int virtualNodeCnt;\n    private final HashFunction customHashFunction;\n\n    public AllocateMessageQueueConsistentHash() {\n        this(10);\n    }\n\n    public AllocateMessageQueueConsistentHash(int virtualNodeCnt) {\n        this(virtualNodeCnt, null);\n    }\n\n    public AllocateMessageQueueConsistentHash(int virtualNodeCnt, HashFunction customHashFunction) {\n        if (virtualNodeCnt < 0) {\n            throw new IllegalArgumentException(\"illegal virtualNodeCnt :\" + virtualNodeCnt);\n        }\n        this.virtualNodeCnt = virtualNodeCnt;\n        this.customHashFunction = customHashFunction;\n    }\n\n    @Override\n    public List<MessageQueue> allocate(String consumerGroup, String currentCID, List<MessageQueue> mqAll,\n        List<String> cidAll) {\n\n        List<MessageQueue> result = new ArrayList<>();\n        if (!check(consumerGroup, currentCID, mqAll, cidAll)) {\n            return result;\n        }\n\n        Collection<ClientNode> cidNodes = new ArrayList<>();\n        for (String cid : cidAll) {\n            cidNodes.add(new ClientNode(cid));\n        }","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/apache/rocketmq/blob/293f5885719fc4aa3619446a1900f58ccfcfdd29/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueConsistentHash.java#L27-L63","documentation":"AllocateMessageQueueConsistentHash's constructor rejects a negative virtualNodeCnt with IllegalArgumentException. Virtual node count multiplies each consumer's presence on the consistent-hash ring; a negative count is meaningless (zero is tolerated but degenerate). Typical healthy values are 10 (the default) and up.","triggerScenarios":"new AllocateMessageQueueConsistentHash(-1) or passing a config-parsed integer that defaulted to -1/'not set' sentinel.","commonSituations":"Reading virtualNodeCnt from a config system where a missing key parses as -1; arithmetic like (nodes - expected) that goes negative when data is wrong.","solutions":["Pass a positive count, e.g. new AllocateMessageQueueConsistentHash(10)","Sanitize config values: Math.max(1, parsedValue)","Treat -1 sentinel from config as 'use default' and substitute 10"],"exampleFix":"// before\nnew AllocateMessageQueueConsistentHash(cfg.getInt(\"vnode\", -1));\n\n// after\nint vnode = cfg.getInt(\"vnode\", 10);\nnew AllocateMessageQueueConsistentHash(Math.max(1, vnode));","handlingStrategy":"validation","validationCode":"int vnode = Math.max(1, configuredVirtualNodeCnt);\nnew AllocateMessageQueueConsistentHash(vnode);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never use -1 as an 'unset' sentinel that flows into constructors","Clamp config-derived counts to >= 1"],"tags":["rebalance","consistent-hash","validation","constructor"],"backgroundTag":null,"analyzedSha":"293f5885719fc4aa3619446a1900f58ccfcfdd29","analyzedAt":"2026-08-14T11:50:13.822Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}