Fix CursorableLinkedList iterator remove/set not throwing IllegalStateException after next-previous-removeByIndex

bug 35766

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@219330 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2005-07-16 14:19:42 +00:00
parent 6adec6b8d4
commit 2cdf3b0ba8
3 changed files with 82 additions and 2 deletions

View File

@ -74,6 +74,7 @@ If this causes major headaches to anyone please contact commons-dev at jakarta.a
<ul>
<li>FastArrayList - Fix iterators and views to work better in multithreaded environments</li>
<li>FastArrayList - Fix iterator remove where ConcurrentModificationException not as expected [34690]</li>
<li>CursorableLinkedList (list subpackage) - Fix iterator remove/set not throwing IllegalStateException after next-previous-removeByIndex [35766]</li>
<li>SetUniqueList.set(int,Object) - Destroyed set status in certain circumstances [33294]</li>
<li>AbstractLinkedMap.init() - Now calls createEntry() to create the map entry object [33706]</li>
<li>AbstractHashedMap deserialization - Fix to prevent doubling of internal data array [34265]</li>

View File

@ -445,9 +445,17 @@ public class CursorableLinkedList extends AbstractLinkedList implements Serializ
* @param node the node that was removed
*/
protected void nodeRemoved(Node node) {
if (node == next) {
if (node == next && node == current) {
// state where next() followed by previous()
next = node.next;
current = null;
} else if (node == next) {
// state where next() not followed by previous()
// and we are matching next node
next = node.next;
} else if (node == current) {
// state where next() not followed by previous()
// and we are matching current (last returned) node
current = null;
nextIndex--;
} else {

View File

@ -444,7 +444,78 @@ public class TestCursorableLinkedList extends TestAbstractLinkedList {
assertEquals(1, c1.nextIndex());
assertEquals("0", c1.next());
}
//-----------------------------------------------------------------------
public void testInternalState_CursorNextNextPreviousRemoveIndex1ByList() {
list.add("A");
list.add("B");
list.add("C");
CursorableLinkedList.Cursor c1 = list.cursor();
assertEquals("A", c1.next());
assertEquals("B", c1.next());
assertEquals("B", c1.previous());
assertEquals("B", list.remove(1));
assertEquals(true, c1.nextIndexValid);
assertEquals(1, c1.nextIndex);
assertEquals(null, c1.current);
assertEquals("C", c1.next.value);
}
public void testInternalState_CursorNextRemoveIndex1ByList() {
list.add("A");
list.add("B");
list.add("C");
CursorableLinkedList.Cursor c1 = list.cursor();
assertEquals("A", c1.next());
assertEquals("B", list.remove(1));
assertEquals(true, c1.nextIndexValid);
assertEquals(1, c1.nextIndex);
assertEquals("A", c1.current.value);
assertEquals("C", c1.next.value);
}
public void testInternalState_CursorNextNextRemoveIndex1ByList() {
list.add("A");
list.add("B");
list.add("C");
CursorableLinkedList.Cursor c1 = list.cursor();
assertEquals("A", c1.next());
assertEquals("B", c1.next());
assertEquals("B", list.remove(1));
assertEquals(true, c1.nextIndexValid);
assertEquals(1, c1.nextIndex);
assertEquals(null, c1.current);
assertEquals("C", c1.next.value);
}
public void testInternalState_CursorNextNextNextRemoveIndex1ByList() {
list.add("A");
list.add("B");
list.add("C");
list.add("D");
CursorableLinkedList.Cursor c1 = list.cursor();
assertEquals("A", c1.next());
assertEquals("B", c1.next());
assertEquals("C", c1.next());
assertEquals("B", list.remove(1));
assertEquals(false, c1.nextIndexValid);
assertEquals("C", c1.current.value);
assertEquals("D", c1.next.value);
}
//-----------------------------------------------------------------------
public void testEqualsAndHashCode() {
assertTrue(list.equals(list));
assertEquals(list.hashCode(),list.hashCode());