RFR JDK-8012645: Stream methods on BitSet, Random, ThreadLocalRandom, ZipFile

Paul Sandoz paul.sandoz at oracle.com
Mon Apr 29 08:53:45 UTC 2013

On Apr 27, 2013, at 5:01 PM, Alan Bateman <Alan.Bateman at oracle.com> wrote:

> On 27/04/2013 00:08, Henry Jen wrote:
>> Hi,
>> Please review webrev at
>> http://cr.openjdk.java.net/~henryjen/ccc/8012645.0/webrev
>> The API doc in specdiff format is at
>> http://cr.openjdk.java.net/~henryjen/ccc/8012645.0/specdiff
>> Cheers,
>> Henry
> In the ZipFile spec it reads "Entries appear in the {@code Stream} in the order they appear in the ZIP file" but I think the order of the entries in the central directory and this may not be the same as the order of the entries in the archive.
> I'm still a newbie on the Spliterator characteristics so bear with me. In BitSet.stream then the spliterator is created as SORTED, is that right?

Yes, since a stream of increasing int values, corresponding to indexes of set bits, is created (the current index of a set bit is used to obtain the index of the next set bit) i.e. it is doing:

  for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) { }

(Note that primitive streams created from ranges are also sorted/distinct, although we are still working out the edge cases for doubles).

The stream is not bound to the bit set until the terminal operation commences. If the bit set is interfered with during executing of the terminal operation (e.g. function values could update it) then results are undefined. I think we should say:

     * <p>The bit set must remain constant during the execution of the terminal
     * stream operation.  Otherwise, the result of the terminal stream operation is 
     * undefined

(This implementation does not fail-fast with a CME.)

> I'm also wondering about the characteristics when creating the ZipFile and JarFile streams, should it include DISTINCT?

Yes, i think so (like with the file-based streams IIRC), plus it should be IMMUTABLE and NONNULL.

It is also very tempting to write an inner class that implements Iterator and Enumeration over zip entries, so the same class can be used by entries() and streams().


> The tests looks good. One suggestion for StreamZipEntriesTest is to include a test to check that ISE is thrown when stream is invoked on a closed ZipFile.
> -Alan.

More information about the core-libs-dev mailing list