-
Sub-task
-
Resolution: Duplicate
-
P2
-
None
-
None
Method Collections.nCopies() returns List spliterator of which is expected to be ORDERED.
This is not so in the case of an empty list.
Consider the following code:
boolean ordered = Collections.nCopies(0, new Object()).spliterator().hasCharacteristics(Spliterator.ORDERED);
System.out.println("ordered = " + ordered);
The output will be:
ordered = false
The following JCK tests will fail due to this:
api/java_util/Collections/ncopies/index.html#NCopiesSpliteratorEmpty[characteristics_ORDERED]
api/java_util/Collections/ncopies/index.html#NCopiesSpliteratorEmpty[forEachRemaining_NPE]
api/java_util/Collections/ncopies/index.html#NCopiesSpliteratorEmpty[hasCharacteristics_ORDERED]
api/java_util/Collections/ncopies/index.html#NCopiesSpliteratorEmpty[tryAdvance_NPE]
api/java_util/Collections/ncopies/index.html#NCopiesStream[checkSpliterator]
api/java_util/Collections/ncopies/index.html#NCopiesParallelStream[checkSpliterator]
This is not so in the case of an empty list.
Consider the following code:
boolean ordered = Collections.nCopies(0, new Object()).spliterator().hasCharacteristics(Spliterator.ORDERED);
System.out.println("ordered = " + ordered);
The output will be:
ordered = false
The following JCK tests will fail due to this:
api/java_util/Collections/ncopies/index.html#NCopiesSpliteratorEmpty[characteristics_ORDERED]
api/java_util/Collections/ncopies/index.html#NCopiesSpliteratorEmpty[forEachRemaining_NPE]
api/java_util/Collections/ncopies/index.html#NCopiesSpliteratorEmpty[hasCharacteristics_ORDERED]
api/java_util/Collections/ncopies/index.html#NCopiesSpliteratorEmpty[tryAdvance_NPE]
api/java_util/Collections/ncopies/index.html#NCopiesStream[checkSpliterator]
api/java_util/Collections/ncopies/index.html#NCopiesParallelStream[checkSpliterator]
- duplicates
-
JDK-8022797 Clarify spliterator characteristics for collections containing no elements
-
- Closed
-