United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6189072 Add sometimes fails after clear or drainTo in LinkedBlockingQueue
6189072 : Add sometimes fails after clear or drainTo in LinkedBlockingQueue

Details
Type:
Bug
Submit Date:
2004-11-01
Status:
Closed
Updated Date:
2010-04-02
Project Name:
JDK
Resolved Date:
2004-11-20
Component:
core-libs
OS:
generic
Sub-Component:
java.util.concurrent
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:
6

Related Reports
Backport:
Relates:

Sub Tasks

Description
When the queue is not empty before a call to drainTo or
  clear, subsequent added elements are not accessible.
###@###.### 11/1/04 22:30 GMT

                                    

Comments
SUGGESTED FIX

--- /u/martin/ws/mustang/src/share/classes/java/util/concurrent/LinkedBlockingQueue.java	2004-08-27 15:54:58.702764000 -0700
+++ /u/martin/ws/jsr166/src/share/classes/java/util/concurrent/LinkedBlockingQueue.java	2004-10-31 14:54:45.663173000 -0800
@@ -526,6 +526,8 @@
         fullyLock();
         try {
             head.next = null;
+            head.item = null;
+            last = head;
             if (count.getAndSet(0) == capacity)
                 notFull.signalAll();
         } finally {
@@ -543,6 +545,7 @@
         try {
             first = head.next;
             head.next = null;
+	    last = head;
             if (count.getAndSet(0) == capacity)
                 notFull.signalAll();
         } finally {
@@ -555,6 +558,7 @@
             p.item = null;
             ++n;
         }
+        head.item = null; // Just for GC, so OK if not within lock
         return n;
     }
         
@@ -577,6 +581,9 @@
             }
             if (n != 0) {
                 head.next = p;
+		head.item = null;
+		if (p == null)
+		    last = head;
                 if (count.getAndAdd(-n) == capacity)
                     notFull.signalAll();
             }
###@###.### 11/1/04 22:30 GMT
                                     
2004-11-01
EVALUATION

This is due to lines of clear() being dropped by mistake sometime
  during development, and then propagated into the newer drainTo methods.
  Somehow no TCK or JTREG tests tested this case.
###@###.### 11/1/04 22:30 GMT
                                     
2004-11-01



Hardware and Software, Engineered to Work Together