JDK-8037857 : Methods j.u.Arrays.spliterator/stream(X[], int, int) throw IAE instead of specified AIOOBE when endIndex < startIndex
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.stream
  • Affected Version: emb-8u26,8,8m,8u20,9
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2014-03-19
  • Updated: 2014-08-11
  • Resolved: 2014-03-24
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 JDK 9
8u20Fixed 9 b08Fixed
Description
The new JavaSE8 methods j.u.Arrays.spliterator/stream(X[], int, int) throw IAE instead of the specified AIOOBE when end index is less than start index

For example

http://download.java.net/jdk8/docs/api/java/util/Arrays.html#spliterator-long:A-int-int-
http://download.java.net/jdk8/docs/api/java/util/Arrays.html#stream-double:A-int-int-

Specify
"ArrayIndexOutOfBoundsException - if startInclusive is negative, endExclusive is less than startInclusive, or endExclusive is greater than the array size"

For example this line:

        Arrays.spliterator(new int[]{1, 2, 3, 4, 5}, 2, 1);

will throw "java.lang.IllegalArgumentException: origin(2) > fence(1)"


The following tests which were added to JCK8a (and don't exist in JCK8) fail due to this issue:

api/java_util/Arrays/spliterators/index.html#SpliteratorFromSubArray_Exceptions[endIsLessThanStart]
api/java_util/Arrays/spliterators/index.html#SpliteratorFromLongSubArray_Exceptions[endIsLessThanStart]
api/java_util/Arrays/spliterators/index.html#SpliteratorFromIntSubArray_Exceptions[endIsLessThanStart]
api/java_util/Arrays/spliterators/index.html#SpliteratorFromDoubleSubArray_Exceptions[endIsLessThanStart]

api/java_util/Arrays/streams/index.html#StreamFromDoubleSubArray_Exceptions[endIsLessThanStart]
api/java_util/Arrays/streams/index.html#StreamFromIntSubArray_Exceptions[endIsLessThanStart]   
api/java_util/Arrays/streams/index.html#StreamFromLongSubArray_Exceptions[endIsLessThanStart]  
api/java_util/Arrays/streams/index.html#StreamFromSubArray_Exceptions[endIsLessThanStart]      


Comments
Verified by regression test provided with this fix. Mentioned jck tests (from jck8a) also PASS.
18-04-2014

This is an oversight i suspect from copying Arrays.rangeCheck to Spliterators.checkFromToBounds. Furthermore, there is a slight difference between the checking of spliterator/streams compared to other Arrays methods that throw IllegalArgumentException if origin > fence. Thankfully we can easily fix the former but cannot do anything about the latter.
19-03-2014