JDK-8020669 : (fs) Files.readAllBytes() does not read any data when Files.size() is 0
  • Type: Bug
  • Status: Closed
  • Resolution: Fixed
  • Component: core-libs
  • Sub-Component: java.nio
  • Priority: P4
  • Affected Version: 7
  • OS: linux
  • Submit Date: 2013-07-10
  • Updated Date: 2014-02-12
  • Resolved Date: 2013-08-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u60Fixed 8 b103Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version  " 1.7.0_21 " 
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux dvega-work 3.8.0-26-generic #38-Ubuntu SMP Mon Jun 17 21:43:33 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

Distributor ID: Ubuntu
  Description:    Ubuntu 13.04
  Release:        13.04
Codename:       raring


A DESCRIPTION OF THE PROBLEM :
Many files in  " /proc "  file-system reports 0 bytes size even though they contain useful data.

If you use java.nio.file.Files.readAllBytes() on then, you will not get any data read.

As the documentation of Files.size() says, the result of this function is not always reliable and should not be trusted to determine the actual contents of a file.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use file.nio.file.Files.readAllbytes() to read  " /proc/net/tcp " 

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Byte contents of the file read
ACTUAL -
No bytes read

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Path tcpInfo = Paths.get( " /proc/net/tcp " );
byte[] data = Files.readAllBytes(tcpInfo);
if (data.length == 0) throw new AssertionError( " No data read " );
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Read the bytes with the classic InputStream.read()