You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2024/04/05 00:01:00 UTC

[jira] [Resolved] (IO-854) ThresholdingOutputStream never calls thresholdReached() when threshold < 0

     [ https://issues.apache.org/jira/browse/IO-854?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory resolved IO-854.
--------------------------------
    Fix Version/s: 2.16.1
       Resolution: Fixed

> 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
>            Priority: Major
>             Fix For: 2.16.1
>
>
> 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)