This is an automated email from the ASF dual-hosted git repository. sijie pushed a commit to branch branch-4.7 in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/branch-4.7 by this push: new 0f570e7 Issue #1740: IOUtils.close() only accepts Closeable as a vararg which results in unnecessary Object[] created if only one Closeable passed there 0f570e7 is described below commit 0f570e7da0eaa47bad01507057b97ecd7af83d0e Author: Andrey Yegorov <dl...@users.noreply.github.com> AuthorDate: Fri Oct 5 15:31:28 2018 -0700 Issue #1740: IOUtils.close() only accepts Closeable as a vararg which results in unnecessary Object[] created if only one Closeable passed there Descriptions of the changes in this PR: added close() variant that takes one Closeable. ### Motivation 100% of close() usage is with one Closeable. ### Changes light refactoring. Master Issue: #1740 Author: Andrey Yegorov <ayego...@salesforce.com> Reviewers: Sijie Guo <si...@apache.org>, Enrico Olivelli <eolive...@gmail.com> This closes #1741 from dlg99/nit/ioutils, closes #1740 (cherry picked from commit 117ba4d7e2965f520d98a96a6ada7af54d9947ce) Signed-off-by: Sijie Guo <si...@apache.org> --- .../java/org/apache/bookkeeper/util/IOUtils.java | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/IOUtils.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/IOUtils.java index 53ef2ac..43b6ff3 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/IOUtils.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/IOUtils.java @@ -43,13 +43,26 @@ public class IOUtils { */ public static void close(Logger log, java.io.Closeable... closeables) { for (java.io.Closeable c : closeables) { - if (c != null) { - try { - c.close(); - } catch (IOException e) { - if (log != null && log.isDebugEnabled()) { - log.debug("Exception in closing " + c, e); - } + close(log, c); + } + } + + /** + * Close the Closeable object and <b>ignore</b> any {@link IOException} or + * null pointers. Must only be used for cleanup in exception handlers. + * + * @param log + * the log to record problems to at debug level. Can be null. + * @param closeable + * the objects to close + */ + public static void close(Logger log, java.io.Closeable closeable) { + if (closeable != null) { + try { + closeable.close(); + } catch (IOException e) { + if (log != null && log.isDebugEnabled()) { + log.debug("Exception in closing " + closeable, e); } } }