From 219e986e294e9cc8ed8ebf89038df95cd95e17bd Mon Sep 17 00:00:00 2001 From: Charles Munger Date: Fri, 15 Nov 2019 12:55:55 -0800 Subject: [PATCH] Deprecate FileUtils.closeQuietly This API encourages swallowing errors, and the code to implement it is trivial if apps still want to do it themselves. Guava's reasoning on deprecating their version of this API: https://github.com/google/guava/issues/1118 Test: No behavior changes Bug: 144042891 Change-Id: Ic4cfb7366c65d49c355479f420d9ba4fc1b3f053 --- api/current.txt | 4 ++-- core/java/android/os/FileUtils.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/api/current.txt b/api/current.txt index 1a87b2257d279..1c80fd6066edf 100644 --- a/api/current.txt +++ b/api/current.txt @@ -34533,8 +34533,8 @@ package android.os { } public final class FileUtils { - method public static void closeQuietly(@Nullable AutoCloseable); - method public static void closeQuietly(@Nullable java.io.FileDescriptor); + method @Deprecated public static void closeQuietly(@Nullable AutoCloseable); + method @Deprecated public static void closeQuietly(@Nullable java.io.FileDescriptor); method public static long copy(@NonNull java.io.InputStream, @NonNull java.io.OutputStream) throws java.io.IOException; method public static long copy(@NonNull java.io.InputStream, @NonNull java.io.OutputStream, @Nullable android.os.CancellationSignal, @Nullable java.util.concurrent.Executor, @Nullable android.os.FileUtils.ProgressListener) throws java.io.IOException; method public static long copy(@NonNull java.io.FileDescriptor, @NonNull java.io.FileDescriptor) throws java.io.IOException; diff --git a/core/java/android/os/FileUtils.java b/core/java/android/os/FileUtils.java index f789b723f7329..2ac3def3a3f96 100644 --- a/core/java/android/os/FileUtils.java +++ b/core/java/android/os/FileUtils.java @@ -1275,7 +1275,13 @@ public final class FileUtils { /** * Closes the given object quietly, ignoring any checked exceptions. Does * nothing if the given object is {@code null}. + * + * @deprecated This method may suppress potentially significant exceptions, particularly when + * closing writable resources. With a writable resource, a failure thrown from {@code close()} + * should be considered as significant as a failure thrown from a write method because it may + * indicate a failure to flush bytes to the underlying resource. */ + @Deprecated public static void closeQuietly(@Nullable AutoCloseable closeable) { IoUtils.closeQuietly(closeable); } @@ -1283,7 +1289,13 @@ public final class FileUtils { /** * Closes the given object quietly, ignoring any checked exceptions. Does * nothing if the given object is {@code null}. + * + * @deprecated This method may suppress potentially significant exceptions, particularly when + * closing writable resources. With a writable resource, a failure thrown from {@code close()} + * should be considered as significant as a failure thrown from a write method because it may + * indicate a failure to flush bytes to the underlying resource. */ + @Deprecated public static void closeQuietly(@Nullable FileDescriptor fd) { IoUtils.closeQuietly(fd); }