[9] RFR of 8132539: (fs) Files.lines(path).collect() returns wrong value in JDK 9 with certain files
Chris Hegarty
chris.hegarty at oracle.com
Wed Aug 12 06:55:48 UTC 2015
Good sleuthing Brian. The change looks good.
-Chris
> On 12 Aug 2015, at 02:14, Brian Burkhalter <brian.burkhalter at oracle.com> wrote:
>
> Please review at your convenience.
>
> Issue: https://bugs.openjdk.java.net/browse/JDK-8132539
> Patch: http://cr.openjdk.java.net/~bpb/8132539/webrev.00/
>
> Summary:
>
> As of JDK 9, Files.lines() attempts to use a FileChannelLinesSpliterator as a faster path to emit a Stream<String> than using BufferedReader.lines(). The FileChannelLinesSpliterator constructor requires a fence parameter which is derived from FileChannel.size(). For most files under the /proc directory on Linux, the size obtained from the fstat() function is zero [1] which means that FileChannel.size() will return zero. For such cases the FileChannelLinesSpliterator is created with a zero fence value hence emits a single empty String. The fix proposed in the above patch changes Files simply not to attempt to use the FileChannelLinesSpliterator if FileChannel.size() returns a non-positive value.
>
> Thanks,
>
> Brian
>
> [1] Notes section of http://linux.die.net/man/2/fstat.
More information about the nio-dev
mailing list