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

NullPointerException in LinkedBlockingQueue.peek

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 5.0
    • core-libs

      FULL PRODUCT VERSION :
      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP Pro sp2

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      multiple threads

      A DESCRIPTION OF THE PROBLEM :
      Caused by: java.lang.NullPointerException
                  at java.util.concurrent.LinkedBlockingQueue.peek(LinkedBlockingQueue.java:440)

      this function is

          public E peek() {
              if (count.get() == 0)
                  return null;
              final ReentrantLock takeLock = this.takeLock;
              takeLock.lock();
              try {
                  Node<E> first = head.next;
                  if (first == null)
                      return null;
                  else
                      return first.item;
              } finally {
                  takeLock.unlock();
              }
          }

      line 440 is Node<E> first = head.next;

      i think that you need to add in line 440

              if (count.get() == 0)
                  return null;

      a second time. the difference this time is that you are in a protected section enforced by takeLock.lock();

      thanks.
       


      REPRODUCIBILITY :
      This bug can be reproduced occasionally.

            martin Martin Buchholz
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: