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 2023/10/20 12:54:00 UTC

[jira] [Updated] (IO-590) Is zero a legal buffer size or not?

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

Gary D. Gregory updated IO-590:
-------------------------------
    Affects Version/s:     (was: 3.x)

> Is zero a legal buffer size or not?
> -----------------------------------
>
>                 Key: IO-590
>                 URL: https://issues.apache.org/jira/browse/IO-590
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Utilities
>            Reporter: Hao Zhong
>            Priority: Major
>
> I notice that in the org.apache.commons.io.IOUtils class, zero is considered as a legal buffer size. For example, the code of toByteArray is as follow:
>  
> {code:java}
> public static byte[] toByteArray(final InputStream input, final int size) throws IOException {
> if (size < 0) {
> throw new IllegalArgumentException("Size must be equal or greater than zero: " + size);
> }
> if (size == 0) {
> return new byte[0];
> }
> ...
> }{code}
> The toBufferedReader method does not check buffer sizes. It pass buffer sizes to the underlying Java API:
>  
>  
> {code:java}
> public static BufferedReader toBufferedReader(final Reader reader, final int size) {
> return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader, size);
> }
> {code}
> However, the underlying API considers zero as an illegal input:
>  
>  
> {code:java}
> public BufferedReader(Reader in, int sz) {
> super(in);
> if (sz <= 0)
> throw new IllegalArgumentException("Buffer size <= 0");
> this.in = in;
> cb = new char[sz];
> nextChar = nChars = 0;
> }
> {code}
> I believe that the class shall have the same definition as the underlying API does. Zero shall not be considered as an legal input.
>  



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