JDK-6307455 : LinkedBlockingQueue.toArray(x) does not set "one-past" element of x to null
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2005-08-07
  • Updated: 2010-04-02
  • Resolved: 2005-08-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.0u6Fixed 6 b49Fixed
Description
This program:

import java.util.*;
import java.util.concurrent.*;

public class Bug {
    public static void main(String[] args) throws Throwable {
	Collection<Integer> c = new LinkedBlockingQueue<Integer>();
	Integer[] a = new Integer[1];
	a[0] = 42;
	System.out.println(c.toArray(a)[0]);
    }
}

should print "null", but actually prints 42.

Comments
SUGGESTED FIX --- /tmp/geta4349 2005-08-07 09:38:36.813288200 -0700 +++ LinkedBlockingQueue.java 2005-08-07 09:38:19.919654000 -0700 @@ -499,14 +499,16 @@ if (a.length < size) a = (T[])java.lang.reflect.Array.newInstance (a.getClass().getComponentType(), size); int k = 0; for (Node p = head.next; p != null; p = p.next) a[k++] = (T)p.item; + if (a.length > k) + a[k] = null; return a; } finally { fullyUnlock(); } } public String toString() {
07-08-2005

EVALUATION Yup.
07-08-2005