Details
-
Bug
-
Resolution: Fixed
-
P4
-
15
-
None
Description
See the spec of PriorityBlockingQueue constructor, which accepts the Collection:
https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/concurrent/PriorityBlockingQueue.html#%3Cinit%3E(java.util.Collection)
public PriorityBlockingQueue​(Collection<? extends E> c)
Creates a PriorityBlockingQueue containing the elements in the specified collection. If the specified collection is a SortedSet or a PriorityQueue, this priority queue will be ordered according to the same ordering. Otherwise, this priority queue will be ordered according to the natural ordering of its elements.
The "or a PriorityQueue" part is wrong, which can be demonstrated with the following test:
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.concurrent.PriorityBlockingQueue;
public class PriorityBlockingQueueTest {
public static void main(String[] args) {
PriorityQueue<Integer> pq = new PriorityQueue<>(Comparator.reverseOrder());
PriorityBlockingQueue<Integer> pbq = new PriorityBlockingQueue<>(pq);
System.out.println(pbq.comparator()); // prints null
}
}
So either the spec is wrong and it should tell 'PriorityBlockingQueue' instead of 'PriorityQueue', or the implementation is wrong.
https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/concurrent/PriorityBlockingQueue.html#%3Cinit%3E(java.util.Collection)
public PriorityBlockingQueue​(Collection<? extends E> c)
Creates a PriorityBlockingQueue containing the elements in the specified collection. If the specified collection is a SortedSet or a PriorityQueue, this priority queue will be ordered according to the same ordering. Otherwise, this priority queue will be ordered according to the natural ordering of its elements.
The "or a PriorityQueue" part is wrong, which can be demonstrated with the following test:
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.concurrent.PriorityBlockingQueue;
public class PriorityBlockingQueueTest {
public static void main(String[] args) {
PriorityQueue<Integer> pq = new PriorityQueue<>(Comparator.reverseOrder());
PriorityBlockingQueue<Integer> pbq = new PriorityBlockingQueue<>(pq);
System.out.println(pbq.comparator()); // prints null
}
}
So either the spec is wrong and it should tell 'PriorityBlockingQueue' instead of 'PriorityQueue', or the implementation is wrong.
Attachments
Issue Links
- csr for
-
JDK-8259057 PriorityBlockingQueue constructor spec typo
-
- Closed
-