8014928: (fs) Files.readAllBytes() copies content to new array when content completely read

Martin Buchholz martinrb at google.com
Fri May 24 11:40:19 PDT 2013


Looks good.

ObMartin:

s/Read/Reads/

Array creations of size MAX_VALUE - 8 are much more likely to succeed
than MAX_VALUE


On Fri, May 24, 2013 at 10:49 AM, Alan Bateman <Alan.Bateman at oracle.com>wrote:

>
> This is a trivial one, a performance bug in the private method used by
> Files.readAllBytes to read the file contents.
>
> The bug is that when the byte[] is sized correctly that it will be
> "expanded" in order to read the EOF, then copied a new byte[] of the
> original size. Easily fixed by just bailing when everything is read.
> Technically something could be expanding the file at the time but this is
> inherently racey/unsafe so it's not a concern. The webrev with the proposed
> change is here:
>
> http://cr.openjdk.java.net/~**alanb/8014928/webrev/<http://cr.openjdk.java.net/~alanb/8014928/webrev/>
>
> Thanks,
> Alan.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20130524/9ebbd4dd/attachment.html 


More information about the nio-dev mailing list