PriorityQueue(collection) should throw NPE
martinrb at google.com
Thu May 6 23:13:57 UTC 2010
On Thu, May 6, 2010 at 15:58, David Holmes <David.Holmes at oracle.com> wrote:
> I'm not sure this is necessarily the right fix. It seems to me that
> incidental nulls will be caught in many/most cases by the sorting code for
> collections assumed to contain Comparable's.
The comparator might accept nulls.
But even if it doesn't, it is possible to create a "corrupted" PQ
using the PQ(collection) constructor, and we don't allow
that sort of thing in java.util.
> And we don't need to check when
> filling from an existing PriorityQueue.
Strictly speaking, the source PriorityQueue might be a subclass that
has been modified to accept nulls.
But yes, we could have a version of the fix that only checks for nulls
if the source is not a PQ.
> So is it only the case for filling
> from a SortedSet that needs the explicit null check?
The source can be an arbitrary Collection.
More information about the core-libs-dev