Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-453

Regression in FileUtils.readFileToString from 2.0.1

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1, 2.2, 2.3, 2.4
    • Fix Version/s: 2.5
    • Component/s: Utilities
    • Labels:
      None

      Description

      FileUtils.readFileToString has changed it's behavior to make a call from IOUtils.toByteArray(in) to IOUtils.toByteArray(in, file.length()) in FileUtils.readFileToString. This is a regression because if the file.length = 0, then it will return 0. According to the javadocs for File#length, it is possible to return 0 if it is a System dependent entities, so even though the File.length might return 0, the stream is still open and

      Steps to reproduce (Ubuntu):
      1. Execute nohup sleep 10000 & in a terminal, and get the process id of the sleep command (ps -ef | grep sleep).
      2. Call FileUtils.readFileToString(new File("/proc/$PID/environ")); where $PID is the process ID from step 1.

      You will notice that in 2.0.1 it returns several elements, however in 2.1 it will return nothing.

      See nicolas de loof's comment in https://github.com/apache/commons-io/commit/53a40a6d9dcaaa616b404255406edc30fe2d524c.

        Attachments

        1. IO-453.diff
          0.5 kB
          Steven Christou

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                schristou88 Steven Christou
              • Votes:
                1 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: