Skip to content

Fix LinkedIterator.remove() for the last live element - #10

Open
HaHaWTH wants to merge 1 commit into
Tuinity:masterfrom
HaHaWTH:fix/mt-queue-tail-iterator-remove
Open

Fix LinkedIterator.remove() for the last live element#10
HaHaWTH wants to merge 1 commit into
Tuinity:masterfrom
HaHaWTH:fix/mt-queue-tail-iterator-remove

Conversation

@HaHaWTH

@HaHaWTH HaHaWTH commented Aug 15, 2026

Copy link
Copy Markdown

LinkedIterator.findNext() updates curr only when it finds another live node. When next() returns the last live element, curr remains null or points to the previously returned node, causing the iterator to remove the wrong element.

Logs

Exception found on Paper: https://mclo.gs/SlxTMFc

Minimal reproduce code

public void wwwwwwwww() {
    MultiThreadedQueue<String> queue = new MultiThreadedQueue<>(List.of("A"));
    Iterator<String> itr = queue.iterator();
  
    itr.next(); // A
    itr.remove(); // IllegalStateException
}

Fix

Record the current next node before clearing the final iterator state. This maintains exact-node O(1) removal and keeps MTQueue's concurrent semantics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant