Tuesday, August 23, 2005

LinkedBlockingQueue loses elements

I submitted this bug to Sun but I've got no answer back.


dateCreated: Thu May 26 02:50:20 MDT 2005

description: FULL PRODUCT VERSION :
java version "1.5.0_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode, sharing)



A DESCRIPTION OF THE PROBLEM :
After I put an element into a LinkedBlockingQueue, then remove the element and subsequently add another element to the queue, queue.size() correctly returns 1, but queue.iterator() returns an empty iterator.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
before putting 1 []
before removing 1 [1]
before putting 2 []
AFTER putting 2, q.size() = 1 but q = [2]
The elements are: 2
That's all the queue.

ACTUAL -
before putting 1 []
before removing 1 [1]
before putting 2 []
AFTER putting 2, q.size() = 1 but q = []
The elements are:
That's all the queue.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.concurrent.LinkedBlockingQueue;

public class A {

public static void main(String[] args) throws Exception {

LinkedBlockingQueue<Object> q = new LinkedBlockingQueue<Object>();

System.out.println("before putting 1 " + q);
q.put("1");
System.out.println("before removing 1 " + q);
q.remove("1");
System.out.println("before putting 2 " + q);
q.put("2");


System.out.println("AFTER putting 2, q.size() = " + q.size() + " but q = " + q);

System.out.println("The elements are: ");

for (Object element : q) {
System.out.println("element " + element);
}

System.out.println("That's all the queue.");
}

}

0 Comments:

Post a Comment

<< Home