FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Linux raw 2.6.9 #1 Fri Oct 22 11:25:22 PDT 2004 i686 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
PriorityQueue.remove(Object o) will remove an object with the same priority
as o. If it does not remove o, then that object is lost to the user, since remove does not return the object that was removed.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The test code is supplied below. I define a class that implements Comparable.
I insert one object into a PriorityQueue. I attempt to remove an object that was not inserted into the queue, but has the same priority. PriorityQueue removes the other object.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
PQueue size = 1
PQueue size = 1
ACTUAL -
PQueue size = 1
PQueue size = 0
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.PriorityQueue;
public class PQueueTest implements Comparable {
public int compareTo(Object o) {
return 0;
}
public static void main(String[] args) {
PriorityQueue<PQueueTest> queue = new PriorityQueue<PQueueTest>();
PQueueTest o1 = new PQueueTest();
PQueueTest o2 = new PQueueTest();
queue.add(o1);
System.out.println("PQueue size = " + queue.size());
queue.remove(o2);
System.out.println("PQueue size = " + queue.size());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I redefined compareTo so that it returns 0 only if the two objects are the same
object.
###@###.### 2004-12-14 00:56:47 GMT