commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <>
Subject [jira] [Commented] (IO-365) NullPointerException IOUtils
Date Fri, 01 Feb 2013 10:05:16 GMT


Sebb commented on IO-365:

Javadoc should always say if null is allowed, and if so, what null means.
The Javadoc should also say if methods can return null, and if so, under which circumstances.

But unless null is documented as allowable, the caller should assume it is not allowed.
If an NPE then occurs, then the first thing to check the parameters.

For example, try the following:

char []ca = null;
new String(ca);

Running the code generates an NPE. 

Note that the Javadoc does not state this; it is assumed.


There is one occasion when it might perhaps be worth checking for null (or at least documenting
the behaviour).
That is where the NPE occurs somewhere remote from the called method. That is not the case
> NullPointerException IOUtils
> ----------------------------
>                 Key: IO-365
>                 URL:
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 2.2
>            Reporter: Rustam Matusevic
>            Priority: Trivial
> This is normal way to do like this?
> {code}
>     public static InputStream toInputStream(String input) { // if i put null here?
>         byte[] bytes = input.getBytes();
>         return new ByteArrayInputStream(bytes);
>     }
> {code}
> You might to warn users of framework, you know throw some or handle it.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message