{"record":{"id":"4cac969039e2eca6","repo":"LMAX-Exchange/disruptor","slug":"buffersize-must-not-be-less-than-1","errorCode":null,"errorMessage":"bufferSize must not be less than 1","messagePattern":"bufferSize must not be less than 1","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/lmax/disruptor/AbstractSequencer.java","lineNumber":48,"sourceCode":"    private static final AtomicReferenceFieldUpdater<AbstractSequencer, Sequence[]> SEQUENCE_UPDATER =\n        AtomicReferenceFieldUpdater.newUpdater(AbstractSequencer.class, Sequence[].class, \"gatingSequences\");\n\n    protected final int bufferSize;\n    protected final WaitStrategy waitStrategy;\n    protected final Sequence cursor = new Sequence(Sequencer.INITIAL_CURSOR_VALUE);\n    protected volatile Sequence[] gatingSequences = new Sequence[0];\n\n    /**\n     * Create with the specified buffer size and wait strategy.\n     *\n     * @param bufferSize   The total number of entries, must be a positive power of 2.\n     * @param waitStrategy The wait strategy used by this sequencer\n     */\n    public AbstractSequencer(final int bufferSize, final WaitStrategy waitStrategy)\n    {\n        if (bufferSize < 1)\n        {\n            throw new IllegalArgumentException(\"bufferSize must not be less than 1\");\n        }\n        if (Integer.bitCount(bufferSize) != 1)\n        {\n            throw new IllegalArgumentException(\"bufferSize must be a power of 2\");\n        }\n\n        this.bufferSize = bufferSize;\n        this.waitStrategy = waitStrategy;\n    }\n\n    /**\n     * @see Sequencer#getCursor()\n     */\n    @Override\n    public final long getCursor()\n    {\n        return cursor.get();\n    }","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/LMAX-Exchange/disruptor/blob/c871ca49826a6be7ada6957f6fbafcfecf7b1f87/src/main/java/com/lmax/disruptor/AbstractSequencer.java#L30-L66","documentation":"Thrown by the AbstractSequencer constructor when the ring buffer size passed to a Disruptor/RingBuffer is less than 1. Disruptor requires a strictly positive capacity because the ring buffer is an array-backed circular buffer; a zero or negative size cannot hold any entries. This is a fail-fast configuration error raised before any resource is allocated.","triggerScenarios":"Constructing a Disruptor or RingBuffer with bufferSize <= 0, e.g. new Disruptor<>(factory, 0, threadFactory), or creating a sequencer directly (new MultiProducerSequencer(0, waitStrategy)). Typically happens when the size is computed from configuration, a system property, or an expression that evaluates to 0 (e.g. uninitialised int field, empty list size, integer underflow).","commonSituations":"Size read from a config file/env var that is missing and defaults to 0; capacity derived from partition count or thread count that is 0 in a test environment; off-by-one math producing a negative value; refactoring that moved buffer creation before the size is initialised.","solutions":["Check the value passed as bufferSize and ensure it is >= 1 before constructing the Disruptor.","If the size comes from configuration, validate it at startup and fail with a clear message naming the property.","Choose a power-of-2 size (e.g. 1024, 4096) so you also satisfy the power-of-2 check that runs immediately after this one."],"exampleFix":"// before\nDisruptor<Event> d = new Disruptor<>(Event::new, config.getBufferSize(), threadFactory); // getBufferSize() returns 0\n\n// after\nint size = config.getBufferSize();\nif (size < 1) throw new IllegalArgumentException(\"config.bufferSize must be >= 1, got \" + size);\nDisruptor<Event> d = new Disruptor<>(Event::new, size, threadFactory);","handlingStrategy":"validation","validationCode":"int size = config.getBufferSize();\nif (size < 1) throw new IllegalArgumentException(\"bufferSize must be >= 1, got \" + size);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate all Disruptor sizing inputs at configuration load time, naming the offending property.","Keep buffer sizes as named constants (e.g. RING_SIZE = 1024) instead of computed expressions."],"tags":["disruptor","configuration","constructor","ring-buffer","validation"],"backgroundTag":null,"analyzedSha":"c871ca49826a6be7ada6957f6fbafcfecf7b1f87","analyzedAt":"2026-08-14T14:22:36.358Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}