From 04238bd36a5840739607a39b0d3318a67fbc1648 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 18 May 2019 13:25:31 +0200 Subject: [PATCH] Add CloseableUtil.maybeClose(Closeable) --- .../org/jivesoftware/smack/util/CloseableUtil.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/CloseableUtil.java b/smack-core/src/main/java/org/jivesoftware/smack/util/CloseableUtil.java index e76766d3c..a524c853b 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/CloseableUtil.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/CloseableUtil.java @@ -1,6 +1,6 @@ /** * - * Copyright 2018 Florian Schmaus + * Copyright 2018-2019 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,10 @@ import java.util.logging.Logger; public class CloseableUtil { + public static void maybeClose(Closeable closable) { + maybeClose(closable, null); + } + public static void maybeClose(Closeable closable, Logger logger) { if (closable == null) { return; @@ -31,7 +35,9 @@ public class CloseableUtil { try { closable.close(); } catch (IOException e) { - logger.log(Level.WARNING, "Could not close " + closable, e); + if (logger != null) { + logger.log(Level.WARNING, "Could not close " + closable, e); + } } } }