{"record":{"id":"ff5a3927f1744452","repo":"LMAX-Exchange/disruptor","slug":"n-must-be-0-ff5a39","errorCode":null,"errorMessage":"n must be > 0","messagePattern":"n must be > 0","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/lmax/disruptor/SingleProducerSequencer.java","lineNumber":184,"sourceCode":"\n    /**\n     * @see Sequencer#tryNext()\n     */\n    @Override\n    public long tryNext() throws InsufficientCapacityException\n    {\n        return tryNext(1);\n    }\n\n    /**\n     * @see Sequencer#tryNext(int)\n     */\n    @Override\n    public long tryNext(final int n) throws InsufficientCapacityException\n    {\n        if (n < 1)\n        {\n            throw new IllegalArgumentException(\"n must be > 0\");\n        }\n\n        if (!hasAvailableCapacity(n, true))\n        {\n            throw InsufficientCapacityException.INSTANCE;\n        }\n\n        long nextSequence = this.nextValue += n;\n\n        return nextSequence;\n    }\n\n    /**\n     * @see Sequencer#remainingCapacity()\n     */\n    @Override\n    public long remainingCapacity()\n    {","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/LMAX-Exchange/disruptor/blob/c871ca49826a6be7ada6957f6fbafcfecf7b1f87/src/main/java/com/lmax/disruptor/SingleProducerSequencer.java#L166-L202","documentation":"Thrown by SingleProducerSequencer.tryNext(int n) when n < 1. tryNext claims n slots non-blockingly and returns InsufficientCapacityException when the ring is full; only a non-positive claim is invalid input. Same validation as the multi-producer variant, for ProducerType.SINGLE ring buffers.","triggerScenarios":"Calling ringBuffer.tryNext(0) or tryNext(negative) on a single-producer ring — typically a claiming loop whose remaining count reaches 0 on the final iteration.","commonSituations":"Drain loop computes remaining = limit - claimed and calls tryNext(remaining) once too often; decrementing a shared count to 0 before the claim; batching math underflow.","solutions":["Break out of the claiming loop before calling tryNext with a count < 1.","Use the no-arg tryNext() for single-slot claims.","Test the loop's last iteration where remaining hits zero."],"exampleFix":"// before\nlong seq = ringBuffer.tryNext(remaining); // remaining == 0\n\n// after\nif (remaining < 1) break;\nlong seq = ringBuffer.tryNext(remaining);","handlingStrategy":"validation","validationCode":"if (remaining >= 1) { long seq = ringBuffer.tryNext(remaining); /* ... */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Terminate claim loops when the remaining count reaches 0.","Use tryNext() (no-arg) for single-slot claims."],"tags":["disruptor","producer","try-next","batching","validation"],"backgroundTag":null,"analyzedSha":"c871ca49826a6be7ada6957f6fbafcfecf7b1f87","analyzedAt":"2026-08-14T14:22:36.358Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}