sijie closed pull request #1741: Issue #1740: IOUtils.close() only accepts
Closeable as a vararg which results in unnecessary Object[] created if only one
Closeable passed there
URL: https://github.com/apache/bookkeeper/pull/1741
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
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 53ef2ac9f3..43b6ff39c7 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 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);
}
}
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services