diff options
author | Paul Duffin <paulduffin@google.com> | 2015-08-05 15:54:40 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-08-05 15:54:40 +0000 |
commit | 9fbc1eab3de4566ec1637006622f45cfb6bac118 (patch) | |
tree | f620b9d31ebca153d4c4d135091f2a8049ba5879 | |
parent | 21794acf6d9a85c936ac97a3692a5efc06ed1a7b (diff) | |
parent | 95b321369ed8af3c5cf740313ad13ebdc1789541 (diff) | |
download | guava-9fbc1eab3de4566ec1637006622f45cfb6bac118.tar.gz |
am 95b32136: am 7700d858: Merge "Added Closeables.closeQuietly(Closeable) back"
* commit '95b321369ed8af3c5cf740313ad13ebdc1789541':
Added Closeables.closeQuietly(Closeable) back
-rw-r--r-- | guava/src/com/google/common/io/Closeables.java | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/guava/src/com/google/common/io/Closeables.java b/guava/src/com/google/common/io/Closeables.java index d6f618b32..f22e08e32 100644 --- a/guava/src/com/google/common/io/Closeables.java +++ b/guava/src/com/google/common/io/Closeables.java @@ -88,6 +88,32 @@ public final class Closeables { } /** + * Equivalent to calling {@code close(closeable, true)}, but with no IOException in the signature. + * + * @param closeable the {@code Closeable} object to be closed, or null, in which case this method + * does nothing + * @deprecated Where possible, use the + * <a href="http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html"> + * try-with-resources</a> statement if using JDK7 or {@link Closer} on JDK6 to close one or + * more {@code Closeable} objects. This method is deprecated because it is easy to misuse and + * may swallow IO exceptions that really should be thrown and handled. See + * <a href="https://code.google.com/p/guava-libraries/issues/detail?id=1118">Guava issue + * 1118</a> for a more detailed explanation of the reasons for deprecation and see + * <a href="https://code.google.com/p/guava-libraries/wiki/ClosingResourcesExplained"> + * Closing Resources</a> for more information on the problems with closing {@code Closeable} + * objects and some of the preferred solutions for handling it correctly. This method is + * scheduled to be removed after upgrading Android to Guava 17.0. + */ + @Deprecated + public static void closeQuietly(@Nullable Closeable closeable) { + try { + close(closeable, true); + } catch (IOException e) { + logger.log(Level.SEVERE, "IOException should not have been thrown.", e); + } + } + + /** * Closes the given {@link InputStream}, logging any {@code IOException} that's thrown rather * than propagating it. * |