JDK-8142493 : Utility methods to check indexes and ranges doesn't specify behavior when function produces null
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2015-11-11
  • Updated: 2019-07-17
  • Resolved: 2015-11-17
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 9 Other
9 b94Fixed openjdk7uFixed
Related Reports
Relates :  
Description
Each of the following lines

            Objects.checkIndex(1, 1, (a,b) -> null);
            Objects.checkFromToIndex(1, 7, 2,  (a,b) -> null);
            Objects.checkFromIndexSize(1, 7, 2,  (a,b) -> null);

produce NPE however this behavior doesn't seem to be specified by JDK-8135248

If would be helpful to have the spec mention these thrown NPEs



Comments
IndexOutOfBoundsException looks more natural in this particular case than NPE
11-11-2015

A null function argument maps to an IndexOutOfBoundsException, so perhaps a null return from the function should do the same.
11-11-2015