{"record":{"id":"d07594704f0805a3","repo":"netty/netty","slug":"initialcapacity-d-expected-not-greater-than-ma","errorCode":null,"errorMessage":"initialCapacity: %d (expected: not greater than maxCapacity(%d)","messagePattern":"initialCapacity: (.+?) \\(expected: not greater than maxCapacity\\((.+?)\\)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"buffer/src/main/java/io/netty/buffer/AbstractByteBufAllocator.java","lineNumber":210,"sourceCode":"    @Override\n    public CompositeByteBuf compositeHeapBuffer(int maxNumComponents) {\n        return toLeakAwareBuffer(new CompositeByteBuf(this, false, maxNumComponents));\n    }\n\n    @Override\n    public CompositeByteBuf compositeDirectBuffer() {\n        return compositeDirectBuffer(DEFAULT_MAX_COMPONENTS);\n    }\n\n    @Override\n    public CompositeByteBuf compositeDirectBuffer(int maxNumComponents) {\n        return toLeakAwareBuffer(new CompositeByteBuf(this, true, maxNumComponents));\n    }\n\n    private static void validate(int initialCapacity, int maxCapacity) {\n        checkPositiveOrZero(initialCapacity, \"initialCapacity\");\n        if (initialCapacity > maxCapacity) {\n            throw new IllegalArgumentException(String.format(\n                    \"initialCapacity: %d (expected: not greater than maxCapacity(%d)\",\n                    initialCapacity, maxCapacity));\n        }\n    }\n\n    /**\n     * Create a heap {@link ByteBuf} with the given initialCapacity and maxCapacity.\n     */\n    protected abstract ByteBuf newHeapBuffer(int initialCapacity, int maxCapacity);\n\n    /**\n     * Create a direct {@link ByteBuf} with the given initialCapacity and maxCapacity.\n     */\n    protected abstract ByteBuf newDirectBuffer(int initialCapacity, int maxCapacity);\n\n    @Override\n    public String toString() {\n        return StringUtil.simpleClassName(this) + \"(directByDefault: \" + directByDefault + ')';","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/netty/netty/blob/70040aacae241e9ba371e758f5b86e470bd77ad1/buffer/src/main/java/io/netty/buffer/AbstractByteBufAllocator.java#L192-L228","documentation":"Thrown by AbstractByteBufAllocator.validate as an IllegalArgumentException when allocating a buffer/composite with initialCapacity greater than maxCapacity. Netty requires the initial allocation to fit within the declared ceiling so a caller cannot accidentally request more than the configured maximum at construction time.","triggerScenarios":"Calling alloc.buffer(initial, max) or alloc.heapBuffer/directBuffer/compositeBuffer with initialCapacity > maxCapacity; computing both from config where they were set inconsistently.","commonSituations":"Misconfigured bootstrap/allocator options where initial and max pool sizes were edited independently; copy-pasting allocation calls and bumping only one of the two numbers.","solutions":["Ensure initialCapacity <= maxCapacity in every alloc.* call; derive both from a single validated config.","If maxCapacity should equal initialCapacity, pass the same value or omit max (defaults to Integer.MAX_VALUE).","Add a startup assertion: checkArgument(initialCapacity <= maxCapacity) before bootstrapping."],"exampleFix":"// before\nByteBuf b = alloc.buffer(8192, 4096); // 8192 > 4096\n\n// after\nByteBuf b = alloc.buffer(4096, 8192); // initial <= max","handlingStrategy":"validation","validationCode":"// Validate allocator args before construction\nif (initialCapacity > maxCapacity) {\n    throw new IllegalArgumentException(\"initialCapacity > maxCapacity\");\n}\nByteBuf b = alloc.buffer(initialCapacity, maxCapacity);","typeGuard":"static boolean validAllocArgs(int initial, int max) {\n    return initial >= 0 && max >= 0 && initial <= max;\n}","tryCatchPattern":null,"preventionTips":["Derive initial and max capacity from a single validated config source.","Omit maxCapacity when you want the default (Integer.MAX_VALUE).","Add a startup assertion on allocator configuration."],"tags":["netty","allocator","capacity","illegal-argument","configuration"],"backgroundTag":null,"analyzedSha":"70040aacae241e9ba371e758f5b86e470bd77ad1","analyzedAt":"2026-08-14T01:29:15.551Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}