JDK-6189072 : Add sometimes fails after clear or drainTo in LinkedBlockingQueue
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2004-11-01
  • Updated: 2010-04-02
  • Resolved: 2004-11-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6
5.0u2Fixed 6 b14Fixed
Related Reports
Relates :  
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
01-11-2004

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
01-11-2004