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

DiskFileItem#write can lose original IO error

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.4
    • Labels:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: