TreeMap and TreeSet bug

Hi

I believe you have a severe bug in java.util.AbstractTreeMapImpl that is effecting both java.util.TreeMap and java.util.TreeSet.

This bug can be easily recreated by just adding and then removing a large ammount of items from these collections. The remove() operation results in an exception, and, in some cases causes full consumption of cpu.

This bug occurs both in Visual J# 1.1 and 2.0.

"bug form #1" causes a more severe results than "bug form #2" and eventually causes a full consumption of the cpu (with iternum=1000, for example). Looks like it causes an endless loop in java.util.AbstractTreeMapImpl.removeFixup(...).

public static void TreeSetBug(int iternum)
{
System.out.println("Testing TreeSet bug");
java.util.TreeSet ts = new java.util.TreeSet();
for (int i = 0; i < iternum; i++) {
ts.add(Integer.toString(i));
}

for (int i = iternum - 1; i >= 0; i--) {// bug form #1
// for (int i = 0; i < iternum; i++) { // bug form #2
try {
ts.remove(Integer.toString(i));
}catch(Exception e) {
System.out.println("cannot remove \"" + i + "\"");
}
}
}

public static void TreeMapBug(int iternum)
{
System.out.println("Testing TreeMap bug");
java.util.TreeMap tm = new java.util.TreeMap();
for (int i = 0; i < iternum; i++) {
tm.put(Integer.toString(i),Integer.toString(i));
}

for (int i = iternum - 1; i >= 0; i--) {// bug form #1
// for (int i = 0; i < iternum; i++) { // bug form #2
try {
tm.remove(Integer.toString(i));
}catch(Exception e) {
System.out.println("cannot remove \"" + i + "\"");
}
}
}



Answer this question

TreeMap and TreeSet bug

  • urraca

    Hi

    We have noted this scenario where you are facing the issue mentioned above.. Let me get back to you on this.

    Thanks

    With regards
    Ashwin Raja



  • TreeMap and TreeSet bug