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

Collections.emptyList().sort((Comparator)null) throws NPE

XMLWordPrintable

      The following line

              Collections.emptyList().sort((Comparator)null);

      Leads to

      Exception in thread "main" java.lang.NullPointerException
      at java.util.Objects.requireNonNull(Objects.java:203)
      at java.util.Collections$EmptyList.sort(Collections.java:4523)

      While the spec on j.u.List.sort(Comparator) says:
      "A null value indicates that the elements' natural ordering should be used"


      In the implementation this looks like a result of a copy-paste mistake.

      The following JCK test will fail:

      api/java_util/Collections/empty/EmptyListSort.html#EmptyListSort[elementSettingNotSupported_naturalSorting]


            psandoz Paul Sandoz
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: