commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bernd Eckenfels (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (IO-564) The rules of ByteArrayOutputStream.write are not documented.
Date Mon, 25 Dec 2017 14:24:00 GMT

    [ https://issues.apache.org/jira/browse/IO-564?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16303286#comment-16303286
] 

Bernd Eckenfels commented on IO-564:
------------------------------------

The functionality is defined in the `java.io.OutputStream`. It defines in the description
some of the runtime exceptions. I am not sure if we should duplicate the description. Maybe
inherit the doc?

> If off is negative, or len is negative, or off+len is greater than the length of the
array b,
> then an IndexOutOfBoundsException is thrown.

Also when we copy the description, should we use @throws for IOOBE and NPE?

> The rules of ByteArrayOutputStream.write are not documented.
> ------------------------------------------------------------
>
>                 Key: IO-564
>                 URL: https://issues.apache.org/jira/browse/IO-564
>             Project: Commons IO
>          Issue Type: Improvement
>          Components: Streams/Writers
>    Affects Versions: 2.6
>            Reporter: Hao Zhong
>
> When I call the ByteArrayOutputStream.write method, it returns exceptions. Its API document
 is not quite useful, since it does not define any rules. From the thrown exceptions, I cannot
get any useful information either. Until I read the code, I understand its usage:
> {code}
>  public void write(final byte[] b, final int off, final int len) {
>  if ((off < 0)
>                 || (off > b.length)
>                 || (len < 0)
>                 || ((off + len) > b.length)
>                 || ((off + len) < 0)) {
>             throw new IndexOutOfBoundsException();
>         } else if (len == 0) {
>             return;
>         }
> ...
> }
> {\code}
> Would you please explicitly introduce the rules in the doucment? Or, would you please
add more messages to the thrown exception? Both ways can make the API easier to understand.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message