On Fri, 7 Aug 2020 at 14:27, <ggreg...@apache.org> wrote:
>
> This is an automated email from the ASF dual-hosted git repository.
>
> ggregory pushed a commit to branch master
> in repository https://gitbox.apache.org/repos/asf/commons-io.git
>
>
> The following commit(s) were added to refs/heads/master by this push:
>      new f382ada  Null-guard IOUtils.close(Closeable, IOConsumer).
> f382ada is described below
>
> commit f382ada1a767b9198fb9adf8cd2260a68cd6b8cd
> Author: Gary Gregory <gardgreg...@gmail.com>
> AuthorDate: Fri Aug 7 09:27:12 2020 -0400
>
>     Null-guard IOUtils.close(Closeable, IOConsumer).
> ---
>  src/changes/changes.xml                          | 3 +++
>  src/main/java/org/apache/commons/io/IOUtils.java | 4 +++-
>  2 files changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/src/changes/changes.xml b/src/changes/changes.xml
> index df461c5..bd2f091 100644
> --- a/src/changes/changes.xml
> +++ b/src/changes/changes.xml
> @@ -89,6 +89,9 @@ The <action> type attribute can be add,update,fix,remove.
>        <action dev="ggregory" type="add" due-to="Gary Gregory">
>          Add PathUtils.getAclEntryList(Path).
>        </action>
> +      <action dev="ggregory" type="add" due-to="Gary Gregory">
> +        Null-guard IOUtils.close(Closeable, IOConsumer).
> +      </action>
>        <action dev="ggregory" type="fix" due-to="Gary Gregory">
>          Replace FindBugs with SpotBugs.
>        </action>
> diff --git a/src/main/java/org/apache/commons/io/IOUtils.java 
> b/src/main/java/org/apache/commons/io/IOUtils.java
> index a9b1122..73a2bb9 100644
> --- a/src/main/java/org/apache/commons/io/IOUtils.java
> +++ b/src/main/java/org/apache/commons/io/IOUtils.java
> @@ -372,9 +372,11 @@ public class IOUtils {
>       * @since 2.7
>       */
>      public static void close(final Closeable... closeables) throws 
> IOException {
> -            for(Closeable closeable : closeables) {
> +        if (closeables != null) {
> +            for (Closeable closeable : closeables) {
>                  if (closeable != null) {
>                      closeable.close();
> +                }

Are you sure this is necessary?
AFAICT there is already a test that calls the method with null:

IOUtilsTestCase.testCloseMulti
assertDoesNotThrow(() -> IOUtils.close((Closeable[]) null));

I tried to cause an NPE and failed, so I did not add the outer Null check.
Is there a test case which shows the need for the check?


>              }
>          }
>      }
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to