Skip to content

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

Merged
Spottedleaf merged 1 commit into
Tuinity:masterfrom
HaHaWTH:fix/mt-queue-tail-iterator-remove
Aug 21, 2026
Merged

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

Conversation

@HaHaWTH

@HaHaWTH HaHaWTH commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

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.

@Spottedleaf
Spottedleaf merged commit deec645 into Tuinity:master Aug 21, 2026
@HaHaWTH
HaHaWTH deleted the fix/mt-queue-tail-iterator-remove branch August 22, 2026 03:51
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.

2 participants