Description
According to the code in the v2.8.0 release, passing null to the method should throw an exception, however it is producing an empty byte array instead.
/** * Gets the contents of an <code>InputStream</code> as a <code>byte[]</code>. * <p> * This method buffers the input internally, so there is no need to use a * <code>BufferedInputStream</code>. * </p> * * @param input the <code>InputStream</code> to read from * @return the requested byte array * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs */ public static byte[] toByteArray(final InputStream input) throws IOException { try (final ByteArrayOutputStream output = new ByteArrayOutputStream()) { copy(input, output); return output.toByteArray(); } }
This can be recreated by the following:
@Test public void shouldThrowNullPointerException() { assertThrows(NullPointerException.class, () -> IOUtils.toByteArray((InputStream) null)) }
On v2.7 the test passes, on v2.8.0 it fails.
Attachments
Issue Links
- is related to
-
IO-690 IOUtils.toByteArray(null) no longer throws a NullPointerException
-
- Resolved
-