I was looking into a bug in FileUpload 2.0.0-M1 and tracked it down to a misuse 
of BoundedInputStream.onMaxLength. The reason I'm sending this email before 
submitting a patch to FileUpload is that I believe this behavior is unexpected 
enough to warrant a little extra in the onMaxLength docstring.
The onMaxLength method's docs say:

> A caller has caused a request that would cross the {@code maxLength} boundary.

This is correct, but it may not be immediately obvious that checking an EOF 
counts as crossing the boundary. This means that onMaxLength will trigger if 
the length of the stream is *equal* to the maxLength.

This is unavoidable without a buffer, as you always need to read one more byte 
to determine whether the stream has ended. If you have a stream of 6 bytes, you 
need to read 7 in order to check whether the last byte is an EOF or not.

So perhaps the documentation could be modified to something like:

> A caller has caused a request that would cross the {@code maxLength} 
> boundary. This includes reads that return end of stream. Therefore streams 
> whose length is exactly equal to maxLength will also trigger this method.

--
James Reeves

Reply via email to