Collections.nCopies(0, T).spliterator() is not ORDERED as expected

XMLWordPrintable

      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]


            Assignee:
            Paul Sandoz
            Reporter:
            Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: