Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Not A Problem
-
None
-
None
-
None
Description
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:
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]; } ... }
The toBufferedReader method does not check buffer sizes. It pass buffer sizes to the underlying Java API:
public static BufferedReader toBufferedReader(final Reader reader, final int size) { return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader, size); }
However, the underlying API considers zero as an illegal input:
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; }
I believe that the class shall have the same definition as the underlying API does. Zero shall not be considered as an legal input.