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

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

    XMLWordPrintable

Details

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

    Description

      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();
          }
      }

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: