[Kaffe] I am getting a ConcurrentModificationException
Moses DeJong
dejong at cs.umn.edu
Mon Sep 27 09:53:25 PDT 1999
> However, this exception indicates that your program potentially
> has a bug.. it's trying to iterate through the elements while
> changing the contents of the Hashtable at the same time.
>
> -Archie
I wrote a little test program to double check that what I was doing
was correct. I was using the Hashtable.keys() method to iterate a
table and remove each key like the following example.
import java.util.*;
public class HashTest {
public static void main(String[] argv) {
Hashtable h = new Hashtable();
Enumeration search;
String elem;
h.put("one", new Integer(1));
h.put("two", new Integer(2));
h.put("three", new Integer(3));
for (search = h.keys(); search.hasMoreElements() ; ) {
elem = (String) search.nextElement();
System.out.print("elem is \"" + elem + "\" value is " +
h.get(elem) + " ... ");
h.remove(elem);
System.out.println("removed");
}
}
}
This program works just fine in JDK 1.1.7 from Blackdown.
% java HashTest
elem is "one" value is 1 ... removed
elem is "three" value is 3 ... removed
elem is "two" value is 2 ... removed
With Archie's latest changes it also works under with Kaffe from the CVS
(Mon Sep 27)
% kaffe HashTest
elem is "three" value is 3 ... removed
elem is "one" value is 1 ... removed
elem is "two" value is 2 ... removed
So it looks like this problem has been solved. Thanks Archie.
Later
Mo DeJong
More information about the kaffe
mailing list