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

ThresholdingOutputStream never calls thresholdReached() when threshold < 0

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.16.0
    • 2.16.1
    • Streams/Writers
    • None

    Description

      After 2.16.0, if ThresholdingOutputStream is created with a threshold less than 0, such as -1, it will never call thresholdReached().

      Specifically, in checkThreshold(final int count), thresholdExceeded is now already true, so the condition is never met.

       

      if (!thresholdExceeded && written + count > threshold) {
          thresholdExceeded = true;
          thresholdReached();
      }

       

      This leads to a problem in DeferredFileOutputStream, because it extends ThresholdingOutputStream. DeferredFileOutputStream relies on thresholdReached() to know when to create a temp file. Now the temp file is never created. This, in turn, leads to a problem in commons-fileupload DiskFileItem. This, in turn, leads to problem in Struts2 JakartaMultiPartRequest.

      It seems an oversight that thresholdReached() is never called. The documentation for that method says:

      Indicates that the configured threshold has been reached, and that a subclass should take whatever action necessary on this event. This may include changing the underlying output stream.

      There is now no longer any notification to subclasses, which can cause a cascade of problems.

      This seems to be the commit that introduced the change: https://github.com/apache/commons-io/commit/4f144cf02cfb5f72184bfef40efd8f99a4278ba8, seems to be related to IO-405.

      Attachments

        Activity

          People

            Unassigned Unassigned
            worpet Bill Orpet
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: