RFR of 8132539: (fs) Files.lines(path).collect() returns wrong value in JDK 9 with certain files
brian.burkhalter at oracle.com
Wed Aug 12 01:14:44 UTC 2015
Please review at your convenience.
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  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.
 Notes section of http://linux.die.net/man/2/fstat.
More information about the nio-dev