JDK-8023367 : Collections.emptyList().sort((Comparator)null) throws NPE
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2013-08-20
  • Updated: 2013-08-30
  • Resolved: 2013-08-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b105Fixed
Related Reports
Relates :  
Description
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]