{"record":{"id":"42e7e818d5c7e2f8","repo":"LMAX-Exchange/disruptor","slug":"maxbatchsize-must-be-greater-than-0","errorCode":null,"errorMessage":"maxBatchSize must be greater than 0","messagePattern":"maxBatchSize must be greater than 0","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/lmax/disruptor/BatchEventProcessor.java","lineNumber":61,"sourceCode":"    private final Sequence sequence = new Sequence(Sequencer.INITIAL_CURSOR_VALUE);\n    private final RewindHandler rewindHandler;\n    private int retriesAttempted = 0;\n\n    BatchEventProcessor(\n            final DataProvider<T> dataProvider,\n            final SequenceBarrier sequenceBarrier,\n            final EventHandlerBase<? super T> eventHandler,\n            final int maxBatchSize,\n            final BatchRewindStrategy batchRewindStrategy\n    )\n    {\n        this.dataProvider = dataProvider;\n        this.sequenceBarrier = sequenceBarrier;\n        this.eventHandler = eventHandler;\n\n        if (maxBatchSize < 1)\n        {\n            throw new IllegalArgumentException(\"maxBatchSize must be greater than 0\");\n        }\n        this.batchLimitOffset = maxBatchSize - 1;\n\n        this.rewindHandler = eventHandler instanceof RewindableEventHandler\n                ? new TryRewindHandler(batchRewindStrategy)\n                : new NoRewindHandler();\n    }\n\n    @Override\n    public Sequence getSequence()\n    {\n        return sequence;\n    }\n\n    @Override\n    public void halt()\n    {\n        running.set(HALTED);","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/LMAX-Exchange/disruptor/blob/c871ca49826a6be7ada6957f6fbafcfecf7b1f87/src/main/java/com/lmax/disruptor/BatchEventProcessor.java#L43-L79","documentation":"Thrown by the BatchEventProcessor constructor when maxBatchSize is less than 1. The processor pre-computes batchLimitOffset = maxBatchSize - 1 to cap how many events it claims per batch; a maxBatchSize of 0 or negative makes that offset meaningless and would break batch iteration.","triggerScenarios":"Building a BatchEventProcessor (directly or via BatchEventProcessorBuilder with maxBatchSize(...)) and passing 0 or a negative value, e.g. builder.maxBatchSize(0).build(...).","commonSituations":"maxBatchSize is made configurable and defaults to 0 when unset; it is computed from a batch-limit property parsed incorrectly; copy-paste from code where the parameter meant 'offset' rather than 'size' (off-by-one: passing maxBatchSize - 1).","solutions":["Pass a maxBatchSize >= 1 (the default is typically the full buffer size when batching is unlimited).","If the value comes from config, validate it at load time and apply a sane minimum (e.g. Math.max(1, configured)).","Check you are not passing an already-decremented offset — the API expects the size itself."],"exampleFix":"// before\nBatchEventProcessorBuilder builder = new BatchEventProcessorBuilder();\nbuilder.maxBatchSize(config.getBatchLimit() - 1); // config returns 1 -> 0\n\n// after\nbuilder.maxBatchSize(Math.max(1, config.getBatchLimit()));","handlingStrategy":"validation","validationCode":"int maxBatch = Math.max(1, config.getMaxBatchSize());\nbuilder.maxBatchSize(maxBatch);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat batching limits as config with a documented minimum of 1.","Remember the parameter is a size, not an offset (no -1 needed)."],"tags":["disruptor","configuration","batching","event-processor","validation"],"backgroundTag":null,"analyzedSha":"c871ca49826a6be7ada6957f6fbafcfecf7b1f87","analyzedAt":"2026-08-14T14:22:36.358Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}