I am getting these exceptions, which at first I thought I might be doing something wrong, but now I am convinced something screwy is going on. Here are some code snippets:
private ArrayList<Cell> neighbors = new ArrayList<Cell>();
...
Cell n;
while (neighbors.size() != 0) {
System.out.println("Size = " + neighbors.size());
n = neighbors.remove(0);
...
}
neighbors is only used in this one method, and I synchronized it to make sure threading was not an issue. The size is always between 0 and 6.
This is the first exception I saw:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.remove(ArrayList.java:387)
....
Here is the second one (after I added in the size):
Size = 3
java.lang.IndexOutOfBoundsException: Index: 0, Size: -1940834040
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.remove(ArrayList.java:387)
...
I'm running Java 1.6.0_01 on Fedora 7. Any ideas what could cause this?