RFR [8054029] (fc) FileChannel.size() returns 0 for block devices

Alan Bateman Alan.Bateman at oracle.com
Fri Sep 12 14:28:43 UTC 2014


On 12/09/2014 15:04, Ivan Gerasimov wrote:
> Hello!
>
> There was an edge case found, where FileChannel.size() reports wrong 
> size: This is for block device on Linux.
> That's due to limitation of stat on Linux, which reports the size of 
> block special devices to be zero.
>
> The proposed solution is to explicitly check, if we deal with a block 
> device, and use the ioctl() call with the special flag.
>
> BUGURL: https://bugs.openjdk.java.net/browse/JDK-8054029
> WEBREV: http://cr.openjdk.java.net/~igerasim/8054029/0/webrev/
>
> The solution isn't perfect, in particular, because we still are 
> getting zero from j.nio.Files.size().
>
> A test is provided with the fix, though I marked it as ignored.
> This is because the access to the special devices normally needs the 
> root permissions.
The change looks okay although I don't think we've ever supported using 
this API with block special devices. I assume you will make sure that it 
builds okay on Solaris, Linux, and OS X before pushing.

We should avoid adding tests with @ignore when we can. A few tests check 
if /etc/passwd is writable to know if they are root and pass silently if 
they are not. I don't know if /dev/sda1 is likely on platforms other 
than Linux so you could just skip when not Linux. For better exceptions 
then use FileChannel.open rather than RandomAccessFile.

-Alan.


More information about the nio-dev mailing list