You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by si...@apache.org on 2018/10/05 22:31:33 UTC
[bookkeeper] branch master updated: Issue #1740: IOUtils.close()
only accepts Closeable as a vararg which results in unnecessary Object[]
created if only one Closeable passed there
This is an automated email from the ASF dual-hosted git repository.
sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new 117ba4d Issue #1740: IOUtils.close() only accepts Closeable as a vararg which results in unnecessary Object[] created if only one Closeable passed there
117ba4d is described below
commit 117ba4d7e2965f520d98a96a6ada7af54d9947ce
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 <ay...@salesforce.com>
Reviewers: Sijie Guo <si...@apache.org>, Enrico Olivelli <eo...@gmail.com>
This closes #1741 from dlg99/nit/ioutils, closes #1740
---
.../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);
}
}
}