Details
Description
IOUtils.byteArray(size) should add the verification to assure that the size is legal(size > 0), the illegal(size <=0) should throw IllegalArgumentException.
for an example:
IOUtils.byteArray(-1);
should throw java.lang.NegativeArraySizeException。
fixed code:
/**
- Returns a new byte array of the given size.
* - TODO Consider guarding or warning against large allocations...
* - @param size array size.
- @return a new byte array of the given size.
* - @exception IllegalArgumentException If {@code size <= 0}
* - @since 2.9.0
*/
public static byte[] byteArray(final int size) {
if (size <= 0) { * throw new IllegalArgumentException("byte size <= 0"); * }return new byte[size];
}
test code:IOUtilsTest.java
@Test
public void testByteArrayWithIllegalSize() {
try
catch (Exception e)
{ assertEquals(e.getClass().getName(), IllegalArgumentException.class.getName()); }}