[ 
https://issues.apache.org/jira/browse/IO-696?focusedWorklogId=530624&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-530624
 ]

ASF GitHub Bot logged work on IO-696:
-------------------------------------

                Author: ASF GitHub Bot
            Created on: 04/Jan/21 12:03
            Start Date: 04/Jan/21 12:03
    Worklog Time Spent: 10m 
      Work Description: coveralls commented on pull request #181:
URL: https://github.com/apache/commons-io/pull/181#issuecomment-753937383


   
   [![Coverage 
Status](https://coveralls.io/builds/36062022/badge)](https://coveralls.io/builds/36062022)
   
   Coverage remained the same at 88.644% when pulling 
**f7b0581ebdad813129d7e2fe6ee711b57e8aafff on abchaubey:master** into 
**4efd2b276417ff7299881e55293e91d791109451 on apache:master**.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 530624)
    Time Spent: 20m  (was: 10m)

> IOUtils.toByteArray throws inconsistent exceptions
> --------------------------------------------------
>
>                 Key: IO-696
>                 URL: https://issues.apache.org/jira/browse/IO-696
>             Project: Commons IO
>          Issue Type: Bug
>            Reporter: ackelcn
>            Priority: Major
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> The code of this method is as follows:
> {code:java}
> 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];
>         }        final byte[] data = new byte[size];
>         int offset = 0;
>         int read;        while (offset < size && (read = input.read(data, 
> offset, size - offset)) != EOF) {
>             offset += read;
>         }        
>         if (offset != size) {
>             throw new IOException("Unexpected read size. current: " + offset 
> + ", expected: " + size);
>         }        return data;
>     }
> {code}
> When size is below zero, it throws IllegalArgumentException, but when size is 
> not equal to offset, it throws IOException. It is somewhat confusing. It 
> shall throw IOException in both cases, in that both cases check legal sizes. 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to