You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2005/07/14 11:29:39 UTC
DO NOT REPLY [Bug 35733] New: -
Iterator.remove() in UnboundedFifoBuffer does not work
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=35733>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=35733
Summary: Iterator.remove() in UnboundedFifoBuffer does not work
Product: Commons
Version: 3.1
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Collections
AssignedTo: commons-dev@jakarta.apache.org
ReportedBy: schlosser@informatik.tu-darmstadt.de
The implementation of Iterator.remove() in the unbounded fifo buffer is buggy.
It produces an ArrayIndexOutOfBoundExceptions when it needs to swap around the
end of the array to its start.
The code should be:
public void remove() {
if (lastReturnedIndex == -1) {
throw new IllegalStateException();
}
// First element can be removed quickly
if (lastReturnedIndex == head) {
UnboundedFifoBuffer.this.remove();
lastReturnedIndex = -1;
return;
}
// Other elements require us to shift the subsequent elements
/*
* This loop is buggy in the original implementation!
*/
int i = lastReturnedIndex + 1;
while (i != tail) {
buffer[decrement(i)] = buffer[i];
i = increment(i);
}
lastReturnedIndex = -1;
tail = decrement(tail);
buffer[tail] = null;
index = decrement(index);
}
while the original buggy loop is:
// Other elements require us to shift the subsequent elements
int i = lastReturnedIndex + 1;
while (i != tail) {
if (i >= buffer.length) {
buffer[i - 1] = buffer[0];
i = 0;
} else {
buffer[i - 1] = buffer[i];
i++;
}
}
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org