Collections.emptyList().sort() does nothing

Andrej Golovnin andrej.golovnin at
Wed Nov 15 10:21:06 UTC 2017

> On 15/11/17 10:03, Andrej Golovnin wrote:
>> I think we would need to write ugly code in any case as Java 9 has now
>> two empty list implementations: Collections.emptyList() and List.of().
>> Collections.emptyList().sort() does not throw an exception.
>> List.of().sort() throws an exception.
> Well, that's a bug.  Sorting an empty list is perfectly valid, and application
> programmers shouldn't have to special-case it.

I don't think so. I would say that the implementation of
Collections.emptyList() is broken. Collections.emptyList() and
List.of() are not only empty lists. They are also immutable per

Here is another example of an unsortable empty list:

Collections.unmodifiableList(Collections.emptyList()).sort() throws an

> --
> Andrew Haley
> Java Platform Lead Engineer
> Red Hat UK Ltd. <>
> EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671

More information about the core-libs-dev mailing list