{"record":{"id":"aae6b210e66cf2bd","repo":"TheAlgorithms/Java","slug":"queue-is-full","errorCode":null,"errorMessage":"Queue is full","messagePattern":"Queue is full","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/datastructures/queues/CircularQueue.java","lineNumber":76,"sourceCode":"\n    /**\n     * Checks if the queue is full.\n     *\n     * @return {@code true} if the queue has reached its maximum capacity; {@code false} otherwise\n     */\n    public boolean isFull() {\n        return currentSize == size;\n    }\n\n    /**\n     * Adds a new element to the queue. If the queue is full, an exception is thrown.\n     *\n     * @param value the element to be added to the queue\n     * @throws IllegalStateException if the queue is already full\n     */\n    public void enQueue(T value) {\n        if (isFull()) {\n            throw new IllegalStateException(\"Queue is full\");\n        }\n        if (isEmpty()) {\n            beginningOfQueue = 0;\n        }\n        topOfQueue = (topOfQueue + 1) % size;\n        array[topOfQueue] = value;\n        currentSize++;\n    }\n\n    /**\n     * Removes and returns the element at the front of the queue.\n     *\n     * @return the element at the front of the queue\n     * @throws IllegalStateException if the queue is empty\n     */\n    public T deQueue() {\n        if (isEmpty()) {\n            throw new IllegalStateException(\"Queue is empty\");","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/datastructures/queues/CircularQueue.java#L58-L94","documentation":"Thrown by CircularQueue.enQueue(T) as an IllegalStateException when the queue's element count has reached the fixed capacity set at construction. CircularQueue is a bounded, array-backed ring buffer, so inserting beyond capacity is rejected rather than auto-growing. The guard is isFull(), which is true when currentSize == size.","triggerScenarios":"Calling enQueue(value) on a CircularQueue constructed with size N after N elements have already been enqueued without matching deQueue() calls. For example, new CircularQueue<>(3) followed by four enQueue() calls throws on the fourth.","commonSituations":"Producer pushing items faster than consumer drains; capacity sized too small for burst load; forgetting to pair enQueue with deQueue in a request loop; reusing a queue instance across iterations without draining it.","solutions":["Guard the call with queue.isFull() (or check size vs capacity) and either drain, drop, or reject before enQueue.","Increase the capacity passed to the CircularQueue(int size) constructor to cover peak occupancy.","Pair every enQueue with a corresponding deQueue so the ring buffer stays below capacity.","Switch to an unbounded queue (e.g. java.util.ArrayDeque or a LinkedList) if the workload is bursty and unpredictable."],"exampleFix":"// before\nqueue.enQueue(item); // throws if full\n\n// after\nif (queue.isFull()) {\n    queue.deQueue(); // make room\n}\nqueue.enQueue(item);","handlingStrategy":"validation","validationCode":"// before enqueuing into a bounded CircularQueue\nif (!queue.isFull()) {\n    queue.enQueue(item);\n} else {\n    // drain, drop, or back-pressure\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Always pair enQueue with a prior isFull()/size check for bounded queues.","Size the constructor capacity to the worst-case simultaneous occupancy, not the average.","Track enqueue/dequeue counts in the caller so a drain loop cannot overshoot capacity."],"tags":["queue","data-structure","capacity","bounded-queue","java"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}