{"record":{"id":"df41931a60e88b5d","repo":"TheAlgorithms/Java","slug":"size-must-be-greater-than-0","errorCode":null,"errorMessage":"Size must be greater than 0","messagePattern":"Size must be greater than 0","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/datastructures/queues/CircularQueue.java","lineNumber":41,"sourceCode":" * @param <T> the type of elements in this queue\n */\npublic class CircularQueue<T> {\n    private T[] array;\n    private int topOfQueue;\n    private int beginningOfQueue;\n    private final int size;\n    private int currentSize;\n\n    /**\n     * Constructs a CircularQueue with a specified capacity.\n     *\n     * @param size the maximum number of elements this queue can hold\n     * @throws IllegalArgumentException if the size is less than 1\n     */\n    @SuppressWarnings(\"unchecked\")\n    public CircularQueue(int size) {\n        if (size < 1) {\n            throw new IllegalArgumentException(\"Size must be greater than 0\");\n        }\n        this.array = (T[]) new Object[size];\n        this.topOfQueue = -1;\n        this.beginningOfQueue = -1;\n        this.size = size;\n        this.currentSize = 0;\n    }\n\n    /**\n     * Checks if the queue is empty.\n     *\n     * @return {@code true} if the queue is empty; {@code false} otherwise\n     */\n    public boolean isEmpty() {\n        return currentSize == 0;\n    }\n\n    /**","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/datastructures/queues/CircularQueue.java#L23-L59","documentation":"Thrown by the CircularQueue constructor when size < 1. The queue allocates an Object[] of length `size`, so a zero or negative size would create a degenerate array. The library requires at least one slot to be a meaningful FIFO buffer.","triggerScenarios":"Constructing CircularQueue(0) or CircularQueue(-1). Sizing the queue from a config value or computation that yields zero or negative. Sizing from a count of available items when none are available.","commonSituations":"Capacity read from a properties file defaulting to 0. Size computed as `max(a - b, 0)` when a <= b. Environment where the configured buffer size was not set and parsed as 0.","solutions":["Validate `size >= 1` before constructing, and apply a sensible minimum.","Provide a non-zero default in config when the value is missing.","Clamp computed sizes to at least 1.","Fail the configuration load early with a clear message rather than reaching the constructor."],"exampleFix":"// before\nCircularQueue<T> q = new CircularQueue<>(configuredSize);\n\n// after\nint size = Math.max(1, configuredSize);\nCircularQueue<T> q = new CircularQueue<>(size);","handlingStrategy":"validation","validationCode":"int capacity = Math.max(1, configuredSize);\nnew CircularQueue<T>(capacity);","typeGuard":null,"tryCatchPattern":"try {\n    new CircularQueue<T>(size);\n} catch (IllegalArgumentException e) {\n    new CircularQueue<T>(1);\n}","preventionTips":["Validate config-driven sizes against a minimum of 1 before construction.","Provide a non-zero default for missing capacity config.","Fail configuration loading early with a clear message rather than hitting the constructor."],"tags":["queue","capacity","data-structure","invalid-argument","config","java"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}