{"record":{"id":"92c3cda994210752","repo":"apache/rocketmq","slug":"maxnums-0-92c3cd","errorCode":null,"errorMessage":"maxNums <= 0","messagePattern":"maxNums <= 0","errorType":"exception","errorClass":"MQClientException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java","lineNumber":243,"sourceCode":"            throw new MQClientException(\"parse subscription error\", e);\n        }\n    }\n\n    private PullResult pullSyncImpl(MessageQueue mq, SubscriptionData subscriptionData, long offset, int maxNums, boolean block,\n        long timeout)\n        throws MQClientException, RemotingException, MQBrokerException, InterruptedException {\n        this.isRunning();\n\n        if (null == mq) {\n            throw new MQClientException(\"mq is null\", null);\n        }\n\n        if (offset < 0) {\n            throw new MQClientException(\"offset < 0\", null);\n        }\n\n        if (maxNums <= 0) {\n            throw new MQClientException(\"maxNums <= 0\", null);\n        }\n\n        this.subscriptionAutomatically(mq.getTopic());\n\n        int sysFlag = PullSysFlag.buildSysFlag(false, block, true, false);\n\n        long timeoutMillis = block ? this.defaultMQPullConsumer.getConsumerTimeoutMillisWhenSuspend() : timeout;\n\n        boolean isTagType = ExpressionType.isTagType(subscriptionData.getExpressionType());\n        PullResult pullResult = this.pullAPIWrapper.pullKernelImpl(\n            mq,\n            subscriptionData.getSubString(),\n            subscriptionData.getExpressionType(),\n            isTagType ? 0L : subscriptionData.getSubVersion(),\n            offset,\n            maxNums,\n            sysFlag,\n            0,","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/apache/rocketmq/blob/293f5885719fc4aa3619446a1900f58ccfcfdd29/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java#L225-L261","documentation":"Thrown by pullSyncImpl when maxNums (max number of messages per pull request) is zero or negative. The value is forwarded to the pull kernel as the batch size; anything <= 0 would ask the broker for no or a nonsensical number of messages.","triggerScenarios":"DefaultMQPullConsumer.pull(mq, expr, offset, maxNums) with maxNums = 0 or negative; batch size read from configuration that defaults to 0 when unset; passing a computed pullSize that underflows.","commonSituations":"Configuring pullBatchSize to 0 in application properties; reusing a 'limit' variable that is 0 when the caller wants 'unlimited'; copying quick-start code that forgot to set the batch size.","solutions":["Set a positive batch size, typically 32 (a common default) via consumer.setPullBatchSize(...) or the literal argument","Validate configuration at startup: fail fast if the configured pull size is < 1","If a 'no limit' semantic is wanted, clamp to a sane upper bound like 1000 rather than passing 0"],"exampleFix":"// before\nint maxNums = config.getPullBatchSize(); // 0 when unset\nconsumer.pull(mq, \"*\", offset, maxNums);\n\n// after\nint maxNums = Math.max(1, config.getPullBatchSize());\nconsumer.pull(mq, \"*\", offset, maxNums);","handlingStrategy":"validation","validationCode":"int batch = Math.max(1, configuredBatchSize);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default pull batch size to 32 in config","Assert positive numeric config at startup"],"tags":["rocketmq","pull-consumer","batch-size","argument-validation"],"backgroundTag":null,"analyzedSha":"293f5885719fc4aa3619446a1900f58ccfcfdd29","analyzedAt":"2026-08-14T11:50:13.822Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}