Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6815766

LinkedBlockingQueue's iterator can return null if drainTo(c) executes concurrently

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 7
    • 7
    • core-libs
    • None

      Martin Buchholz reports:

      The following test program should never throw,
      but it quickly throws NullPointerException.

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

      public class LBQRace {
          static void checkNotContainsNull(Iterable it) {
              for (Object x : it)
                  if (x == null)
                      throw new NullPointerException();
          }

          public static void main(String[] args) throws Throwable {
              final BlockingQueue q = new LinkedBlockingQueue();

              new Thread() { public void run() {
                  for (;;) {
                      q.offer(1);
                  }}}.start();

              new Thread() { public void run() {
                  for (;;) {
                      List list = new ArrayList();
                      q.drainTo(list);
                      checkNotContainsNull(list);
                  }}}.start();

              new Thread() { public void run() {
                  for (;;) {
                      checkNotContainsNull(q);
                  }}}.start();
          }
      }

            chegar Chris Hegarty
            dholmes David Holmes
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: