Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/util/concurrent/PriorityBlockingQueue.java
          +++ new/src/share/classes/java/util/concurrent/PriorityBlockingQueue.java
↓ open down ↓ 310 lines elided ↑ open up ↑
 311  311      private E extract() {
 312  312          E result;
 313  313          int n = size - 1;
 314  314          if (n < 0)
 315  315              result = null;
 316  316          else {
 317  317              Object[] array = queue;
 318  318              result = (E) array[0];
 319  319              E x = (E) array[n];
 320  320              array[n] = null;
 321      -            Comparator<? super E> cmp = comparator;
 322      -            if (cmp == null)
 323      -                siftDownComparable(0, x, array, n);
 324      -            else
 325      -                siftDownUsingComparator(0, x, array, n, cmp);
      321 +            if (n > 0) {
      322 +                Comparator<? super E> cmp = comparator;
      323 +                if (cmp == null)
      324 +                    siftDownComparable(0, x, array, n);
      325 +                else
      326 +                    siftDownUsingComparator(0, x, array, n, cmp);
      327 +            }
 326  328              size = n;
 327  329          }
 328  330          return result;
 329  331      }
 330  332  
 331  333      /**
 332  334       * Inserts item x at position k, maintaining heap invariant by
 333  335       * promoting x up the tree until it is greater than or equal to
 334  336       * its parent, or is the root.
 335  337       *
↓ open down ↓ 644 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX