United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-8020669 : (fs) Files.readAllBytes() does not read any data when Files.size() is 0

Details
Type:
Bug
Submit Date:
2013-07-10
Status:
Closed
Updated Date:
2014-02-12
Project Name:
JDK
Resolved Date:
2013-08-01
Component:
core-libs
OS:
linux
Sub-Component:
java.nio
CPU:
Priority:
P4
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:
Relates:

Sub Tasks

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()
                                    

Comments



Hardware and Software, Engineered to Work Together