qwerty4030 commented on code in PR #758:
URL: https://github.com/apache/commons-io/pull/758#discussion_r2182019530
##########
src/main/java/org/apache/commons/io/output/AbstractByteArrayOutputStream.java:
##########
@@ -147,7 +147,8 @@ protected void needNewBuffer(final int newCount) {
// Creating new buffer
final int newBufferSize;
if (currentBuffer == null) {
- newBufferSize = newCount;
+ // prevents 0 size buffers
+ newBufferSize = newCount > 0 ? newCount : DEFAULT_SIZE;
Review Comment:
simplest fix I found. Another option is to not allow ANY buffers smaller
than DEFAULT_SIZE. Some things I ran into trying other fixes:
1. if the logic allows an initial 0 size buffer; the next buffer must be >0
size. Then when `toBufferedInputStream` is called the tests fail because
`.available()` returns 0 (for the initial buffer) instead of the actual length
of the data in the next buffer. Also seems like a waste to even call
`InputStream.read` with a 0 size buffer.
2. Technically there is nothing wrong with a BAOS with an initial size of 0,
so we don't want to throw an exception. The docs say the buffer is increased as
needed so hopefully it's fine to default it to `DEFAULT_SIZE` in this case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]