commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matt Kusnierz (JIRA)" <>
Subject [jira] [Commented] (IO-480) IOUtils.closeQuietly can throw NullPointerException
Date Tue, 09 Jun 2015 08:36:00 GMT


Matt Kusnierz commented on IO-480:

If the intended use of this method is to perform a best efforts attempt to close the inputStream
and not to worry about exceptions; doesn't it make sense to simply catch Exceptions instead
of just IOExceptions. I agree that in this case the NullPointerException should not be thrown
in the first place; so the core java FilterInputStream; and/or the JarURLConnectopm$JarUrlInputStream
sub-class is at fault; but there could be any number of other poor inputStream implementations
out there; and closing them quietly is still the goal of this utility method. Otherwise the
user may be forced to re-wrap the call to closeQuietly with another try-catch; which makes
closeQuietly redundant.

> IOUtils.closeQuietly can throw NullPointerException
> ---------------------------------------------------
>                 Key: IO-480
>                 URL:
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 2.4
>            Reporter: Matt Kusnierz
>   Original Estimate: 10m
>  Remaining Estimate: 10m
> The IOUtils#closeQuietly method in its javadoc suggests that ANY exceptions will be ignored.
This is not the case, as the code only catches IOExceptions. As this example stack trace shows,
it is possible for some InputStreams to throw NullPointerExceptions during close:
> java.lang.NullPointerException: null
> 	at ~[na:1.6.0_35]
> 	at$JarURLInputStream.close(
> 	at ~[commons-io-2.1.jar:2.1]
> 	at ~[commons-io-2.1.jar:2.1]
> Close quietly should do as advertised/suggested and catch all Exceptions.

This message was sent by Atlassian JIRA

View raw message