{"record":{"id":"0d4de3c27e600782","repo":"LMAX-Exchange/disruptor","slug":"the-ring-buffer-cannot-accommodate-it-only-has","errorCode":null,"errorMessage":"The ring buffer cannot accommodate {} it only has space for {} entities.","messagePattern":"The ring buffer cannot accommodate (.+?) it only has space for (.+?) entities\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/lmax/disruptor/RingBuffer.java","lineNumber":908,"sourceCode":"    {\n        return sequencer.remainingCapacity();\n    }\n\n    private void checkBounds(final EventTranslator<E>[] translators, final int batchStartsAt, final int batchSize)\n    {\n        checkBatchSizing(batchStartsAt, batchSize);\n        batchOverRuns(translators, batchStartsAt, batchSize);\n    }\n\n    private void checkBatchSizing(final int batchStartsAt, final int batchSize)\n    {\n        if (batchStartsAt < 0 || batchSize < 0)\n        {\n            throw new IllegalArgumentException(\"Both batchStartsAt and batchSize must be positive but got: batchStartsAt \" + batchStartsAt + \" and batchSize \" + batchSize);\n        }\n        else if (batchSize > bufferSize)\n        {\n            throw new IllegalArgumentException(\"The ring buffer cannot accommodate \" + batchSize + \" it only has space for \" + bufferSize + \" entities.\");\n        }\n    }\n\n    private <A> void checkBounds(final A[] arg0, final int batchStartsAt, final int batchSize)\n    {\n        checkBatchSizing(batchStartsAt, batchSize);\n        batchOverRuns(arg0, batchStartsAt, batchSize);\n    }\n\n    private <A, B> void checkBounds(final A[] arg0, final B[] arg1, final int batchStartsAt, final int batchSize)\n    {\n        checkBatchSizing(batchStartsAt, batchSize);\n        batchOverRuns(arg0, batchStartsAt, batchSize);\n        batchOverRuns(arg1, batchStartsAt, batchSize);\n    }\n\n    private <A, B, C> void checkBounds(\n        final A[] arg0, final B[] arg1, final C[] arg2, final int batchStartsAt, final int batchSize)","sourceCodeStart":890,"sourceCodeEnd":926,"githubUrl":"https://github.com/LMAX-Exchange/disruptor/blob/c871ca49826a6be7ada6957f6fbafcfecf7b1f87/src/main/java/com/lmax/disruptor/RingBuffer.java#L890-L926","documentation":"Thrown by RingBuffer.checkBatchSizing during batch publishing when batchSize exceeds the ring buffer capacity. A batch publish claims batchSize consecutive slots; claiming more slots than the ring holds can never succeed (the publisher would have to wait for itself), so it is rejected up front instead of deadlocking.","triggerScenarios":"Calling publishEvents(translators, 0, 5000) on a 1024-entry ring buffer; any batch publish whose count argument is greater than ringBuffer.getBufferSize().","commonSituations":"Batch size from config outgrows a small ring (e.g. tests use bufferSize 8 while production batches are 100); bulk-loading code that publishes an entire list in one call; capacity tuned down for memory without revisiting batch size.","solutions":["Split the batch into chunks of at most ringBuffer.getBufferSize() and publish each chunk.","Or increase the ring buffer size to at least the maximum batch size.","Add a startup check: maxBatchSize <= ringBufferSize."],"exampleFix":"// before\nringBuffer.publishEvents(translators, 0, translators.length); // 5000 into 1024 ring\n\n// after\nint chunk = ringBuffer.getBufferSize();\nfor (int i = 0; i < translators.length; i += chunk) {\n    int n = Math.min(chunk, translators.length - i);\n    ringBuffer.publishEvents(translators, i, n);\n}","handlingStrategy":"validation","validationCode":"int capacity = ringBuffer.getBufferSize();\nif (batchSize > capacity) {\n    for (int i = 0; i < items.size(); i += capacity) {\n        ringBuffer.publishEvents(translators, i, Math.min(capacity, items.size() - i));\n    }\n    return;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Chunk all bulk publishes at ringBuffer.getBufferSize().","Assert maxBatchSize <= ringBufferSize once at startup."],"tags":["disruptor","ring-buffer","batching","capacity","publish"],"backgroundTag":null,"analyzedSha":"c871ca49826a6be7ada6957f6fbafcfecf7b1f87","analyzedAt":"2026-08-14T14:22:36.358Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}