On Sat, 13 Mar 1999, Stuart Ballard wrote:
> Ouch. That's my code... the version of LinkedList that I checked in was
> completely untested other than making sure it compiled, because I
> suddenly found myself without any time available to hack on it, and I
> wanted to get *something* committed. I'll look into it today and
> tomorrow and try to get an at least minimally tested version for you - I
> can't promise though, because my time is still pretty limited. If anyone
> else wants to try to track this down, go for it.
>
> Sorry for the mess,
> Stuart.
>
Found and (AFAIK) fixed it -- it throws a ConcurrentModificationException
when it should, and not when it shouldn't. The problem arises from the
fact that the iterator doesn't know what it's modCount should be, so
anything that iterates (and alot of stuff does due to AbstractCollection),
it fails after the first modification, where modCount would be 1, not 0.
The simple solution was to add a int knownMod to the LinkedList.Iter(...)
constructor, and change it to match in the other places.
A unified diff is attached.
Hope that helps,
=========================================================================
Ross Mellgren, a.k.a. Dridus (/Dry-duhs/)
[EMAIL PROTECTED], [EMAIL PROTECTED], ICQ 413389, http://www.dridus.com/~rmm
=========================================================================
--- ../../../java/util/LinkedList.java Thu Jan 21 20:34:14 1999
+++ LinkedList.java Sat Mar 13 13:58:40 1999
@@ -163,12 +163,13 @@
* @param index the index to begin iteration.
* @exception IndexOutOfBoundsException if index < 0 || index > size.
*/
- Iter(Backing backing, Entry n, int index, int s) {
+ Iter(Backing backing, Entry n, int index, int s, int knownMod) {
b = backing;
pos = index;
size = s;
next = n;
previous = n.previous;
+ this.knownMod = knownMod;
}
public int nextIndex() {
@@ -412,7 +413,7 @@
throw new IndexOutOfBoundsException();
}
- return new Iter(back, getEntry(index, size, ends, ends), index, size);
+ return new Iter(back, getEntry(index, size, ends, ends), index, size, modCount);
}
/**
@@ -487,7 +488,7 @@
throw new IndexOutOfBoundsException();
}
- return new Iter(back, getEntry(index, size, head, tail), index, size);
+ return new Iter(back, getEntry(index, size, head, tail), index, size,
+this.modCount);
}
public void clear() {