Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8020669

(fs) Files.readAllBytes() does not read any data when Files.size() is 0

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 8
    • 7
    • core-libs
    • b103
    • linux
    • Verified

    Backports

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

        Attachments

          Issue Links

            Activity

              People

                igerasim Ivan Gerasimov
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: