Bill Orpet created IO-854:
-----------------------------

             Summary: ThresholdingOutputStream never calls thresholdReached() 
when threshold < 0
                 Key: IO-854
                 URL: https://issues.apache.org/jira/browse/IO-854
             Project: Commons IO
          Issue Type: Bug
          Components: Streams/Writers
    Affects Versions: 2.16.0
            Reporter: Bill Orpet


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.

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

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:
{quote}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.
{quote}
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.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to