Uploaded image for project: 'Commons FileUpload'
  1. Commons FileUpload
  2. FILEUPLOAD-252

DiskFileItem#write can lose original IO error

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.4
    • None

    Description

      The method DiskFileItem#write has the following code:

      FileOutputStream fout = null;
      try {
          fout = new FileOutputStream(file);
          fout.write(get());
      } finally {
          if (fout != null) {
              fout.close();
          }
      }
      

      If the write fails and then the close fails, the write failure will be masked by the close error. It might be better to write the code as:

      FileOutputStream fout = null;
      try {
          fout = new FileOutputStream(file);
          fout.write(get());
          fout.close();
      } finally {
          IOUtils.closeQuietly(fout);
      }
      

      This would ensure that the first error was reported.

      Attachments

        Activity

          People

            Unassigned Unassigned
            sebb Sebb
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: