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

PriorityBlockingQueue allows null value to be added

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 8u261, 14.0.2, 15
    • Fix Version/s: None
    • Component/s: core-libs

      Description

      A DESCRIPTION OF THE PROBLEM :
      in the constructor of PriorityBlockingQueue, some test case would allow null item.( public PriorityBlockingQueue(Collection<? extends E> c))

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run the test case

      ACTUAL -
      run safely

      ---------- BEGIN SOURCE ----------
      import java.util.ArrayList;
      import java.util.Queue;
      import java.util.concurrent.PriorityBlockingQueue;

      public class test16 {
          static class Holder implements Comparable<Holder> {
              int i;
              Holder(int i) {
                  this.i = i;
              }
              public int compareTo(Holder h) {
                  if(h == null)
                      return -1;
                  return this.i - h.i;
              }
          }

          public static void main(String[] args) {
              ArrayList<Holder> al = new ArrayList<>();
              al.add(new Holder(1));
              al.add(new Holder(2));
              al.add(null);
              Queue a = new PriorityBlockingQueue<>(al);
          }
      }

      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              chegar Chris Hegarty
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: