[jira] [Commented] (IO-686) IOUtils.toByteArray(InputStream) Javadoc does not match code
[ https://issues.apache.org/jira/browse/IO-686?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17268104#comment-17268104 ] Gary D. Gregory commented on IO-686: The current Javadoc reads: {code:java} /** * Gets the contents of an {@code InputStream} as a {@code byte[]}. * * This method buffers the input internally, so there is no need to use a * {@code BufferedInputStream}. * * * @param inputStream the {@code InputStream} to read. * @return the requested byte array. * @throws NullPointerException if the InputStream is {@code null}. * @throws IOException if an I/O error occurs. */ {code} > IOUtils.toByteArray(InputStream) Javadoc does not match code > > > Key: IO-686 > URL: https://issues.apache.org/jira/browse/IO-686 > Project: Commons IO > Issue Type: Bug > Components: Utilities >Affects Versions: 2.8.0 >Reporter: Alan Moffat >Priority: Critical > Fix For: 2.9.0 > > > 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. > {code:java} > /** > * Gets the contents of an InputStream as a byte[]. > * > * This method buffers the input internally, so there is no need to use a > * BufferedInputStream. > * > * > * @param input the InputStream 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(); > } > } {code} > This can be recreated by the following: > {code:java} > @Test > public void shouldThrowNullPointerException() { > assertThrows(NullPointerException.class, () -> > IOUtils.toByteArray((InputStream) null)) > } {code} > On v2.7 the test passes, on v2.8.0 it fails. -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Commented] (IO-686) IOUtils.toByteArray(InputStream) Javadoc does not match code
[ https://issues.apache.org/jira/browse/IO-686?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17267579#comment-17267579 ] Alan Moffat commented on IO-686: The original Javadoc explicitly called out the @throws NullPointerExceotion for a null inputstream (see initial comment on this bug report). Based on what you’ve said I would expect this in the Javadoc on master but it’s not. I feel that this should be added in > IOUtils.toByteArray(InputStream) Javadoc does not match code > > > Key: IO-686 > URL: https://issues.apache.org/jira/browse/IO-686 > Project: Commons IO > Issue Type: Bug > Components: Utilities >Affects Versions: 2.8.0 >Reporter: Alan Moffat >Priority: Critical > Fix For: 2.9.0 > > > 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. > {code:java} > /** > * Gets the contents of an InputStream as a byte[]. > * > * This method buffers the input internally, so there is no need to use a > * BufferedInputStream. > * > * > * @param input the InputStream 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(); > } > } {code} > This can be recreated by the following: > {code:java} > @Test > public void shouldThrowNullPointerException() { > assertThrows(NullPointerException.class, () -> > IOUtils.toByteArray((InputStream) null)) > } {code} > On v2.7 the test passes, on v2.8.0 it fails. -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Commented] (IO-686) IOUtils.toByteArray(InputStream) Javadoc does not match code
[ https://issues.apache.org/jira/browse/IO-686?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17267516#comment-17267516 ] Gary D. Gregory commented on IO-686: [~themoffster] This is related to [IO=690], the underlying code in git master is now back to an NPE (with a better message) for null input; the Javadoc is improved as well. > IOUtils.toByteArray(InputStream) Javadoc does not match code > > > Key: IO-686 > URL: https://issues.apache.org/jira/browse/IO-686 > Project: Commons IO > Issue Type: Bug > Components: Utilities >Affects Versions: 2.8.0 >Reporter: Alan Moffat >Priority: Critical > Fix For: 2.9.0 > > > 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. > {code:java} > /** > * Gets the contents of an InputStream as a byte[]. > * > * This method buffers the input internally, so there is no need to use a > * BufferedInputStream. > * > * > * @param input the InputStream 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(); > } > } {code} > This can be recreated by the following: > {code:java} > @Test > public void shouldThrowNullPointerException() { > assertThrows(NullPointerException.class, () -> > IOUtils.toByteArray((InputStream) null)) > } {code} > On v2.7 the test passes, on v2.8.0 it fails. -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Commented] (IO-686) IOUtils.toByteArray(InputStream) Javadoc does not match code
[ https://issues.apache.org/jira/browse/IO-686?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17194894#comment-17194894 ] Alan Moffat commented on IO-686: If there was a test for it why did it not fail the build in 2.8.0? > IOUtils.toByteArray(InputStream) Javadoc does not match code > > > Key: IO-686 > URL: https://issues.apache.org/jira/browse/IO-686 > Project: Commons IO > Issue Type: Bug > Components: Utilities >Affects Versions: 2.8.0 >Reporter: Alan Moffat >Priority: Critical > Fix For: 2.9.0 > > > 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. > {code:java} > /** > * Gets the contents of an InputStream as a byte[]. > * > * This method buffers the input internally, so there is no need to use a > * BufferedInputStream. > * > * > * @param input the InputStream 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(); > } > } {code} > This can be recreated by the following: > {code:java} > @Test > public void shouldThrowNullPointerException() { > assertThrows(NullPointerException.class, () -> > IOUtils.toByteArray((InputStream) null)) > } {code} > On v2.7 the test passes, on v2.8.0 it fails. -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Commented] (IO-686) IOUtils.toByteArray(InputStream) Javadoc does not match code
[ https://issues.apache.org/jira/browse/IO-686?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17194758#comment-17194758 ] Sebb commented on IO-686: - It looks like there was a test for the behaviour: https://github.com/apache/commons-io/blob/6efbccc88318d15c0f5fdcfa0b87e3dc980dca22/src/test/java/org/apache/commons/io/IOUtilsCopyTestCase.java#L99 That suggests the behaviour was intentional. > IOUtils.toByteArray(InputStream) Javadoc does not match code > > > Key: IO-686 > URL: https://issues.apache.org/jira/browse/IO-686 > Project: Commons IO > Issue Type: Bug > Components: Utilities >Affects Versions: 2.8.0 >Reporter: Alan Moffat >Priority: Critical > Fix For: 2.9.0 > > > 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. > {code:java} > /** > * Gets the contents of an InputStream as a byte[]. > * > * This method buffers the input internally, so there is no need to use a > * BufferedInputStream. > * > * > * @param input the InputStream 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(); > } > } {code} > This can be recreated by the following: > {code:java} > @Test > public void shouldThrowNullPointerException() { > assertThrows(NullPointerException.class, () -> > IOUtils.toByteArray((InputStream) null)) > } {code} > On v2.7 the test passes, on v2.8.0 it fails. -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Commented] (IO-686) IOUtils.toByteArray(InputStream) Javadoc does not match code
[ https://issues.apache.org/jira/browse/IO-686?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17193855#comment-17193855 ] Gary Gregory commented on IO-686: - In general, we make the Javadoc match the code, as the code evolves. In this case, that method's Javadoc got out of sync with code. The method is now used from other call sites where the expected result is an empty byte array. Gary > IOUtils.toByteArray(InputStream) Javadoc does not match code > > > Key: IO-686 > URL: https://issues.apache.org/jira/browse/IO-686 > Project: Commons IO > Issue Type: Bug > Components: Utilities >Affects Versions: 2.8.0 >Reporter: Alan Moffat >Priority: Critical > Fix For: 2.9.0 > > > 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. > {code:java} > /** > * Gets the contents of an InputStream as a byte[]. > * > * This method buffers the input internally, so there is no need to use a > * BufferedInputStream. > * > * > * @param input the InputStream 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(); > } > } {code} > This can be recreated by the following: > {code:java} > @Test > public void shouldThrowNullPointerException() { > assertThrows(NullPointerException.class, () -> > IOUtils.toByteArray((InputStream) null)) > } {code} > On v2.7 the test passes, on v2.8.0 it fails. -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Commented] (IO-686) IOUtils.toByteArray(InputStream) Javadoc does not match code
[ https://issues.apache.org/jira/browse/IO-686?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17193809#comment-17193809 ] Alan Moffat commented on IO-686: [~ggregory] is this expected behaviour then? I ask as it's a bit of a breaking change and I was expecting the javadoc to be right as that's how the previous version worked. Your comment suggests that that the code is right and javadoc is wrong which is surprising. > IOUtils.toByteArray(InputStream) Javadoc does not match code > > > Key: IO-686 > URL: https://issues.apache.org/jira/browse/IO-686 > Project: Commons IO > Issue Type: Bug > Components: Utilities >Affects Versions: 2.8.0 >Reporter: Alan Moffat >Priority: Critical > Fix For: 2.9.0 > > > 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. > {code:java} > /** > * Gets the contents of an InputStream as a byte[]. > * > * This method buffers the input internally, so there is no need to use a > * BufferedInputStream. > * > * > * @param input the InputStream 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(); > } > } {code} > This can be recreated by the following: > {code:java} > @Test > public void shouldThrowNullPointerException() { > assertThrows(NullPointerException.class, () -> > IOUtils.toByteArray((InputStream) null)) > } {code} > On v2.7 the test passes, on v2.8.0 it fails. -- This message was sent by Atlassian Jira (v8.3.4#803005)