Files.read/readAllBytes can loop once with zero size buffer

Fabian Lange lange.fabian at gmail.com
Thu Jul 28 20:13:48 UTC 2016


Hi,
I just noticed that when one uses Files.readAllBytes() to read for
example from the Linux proc file system, where file size is claimed to
be 0, Files.read() will allocate a buffer of size 0 before then
adjusting in a second loop (arraycopying the zero size buffer)

In my opinion an initial size of 0 should not be used.
I admit this might be a regression for files which are really empty
and return an empty byte array, but I think it is actually more common
to read from files which incorrectly report to be zero sized.

Fabian


More information about the core-libs-dev mailing list