From b2baf48809bac380c23fb585635f917a594ec748 Mon Sep 17 00:00:00 2001 From: cpovirk Date: Mon, 11 Dec 2023 14:24:03 -0800 Subject: [PATCH] Make the backport's `ClosingFuture` catch any `Exception`, even though only some kinds are theoretically possible. This is a followup to cl/587701612. I had missed this occurrence because it appears only in the backport. RELNOTES=n/a PiperOrigin-RevId: 589948821 --- .../common/util/concurrent/ClosingFuture.java | 13 +++++++++++-- .../common/util/concurrent/ClosingFuture.java | 8 ++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/android/guava/src/com/google/common/util/concurrent/ClosingFuture.java b/android/guava/src/com/google/common/util/concurrent/ClosingFuture.java index 3d7850ee3afa..9b3f89f36ce4 100644 --- a/android/guava/src/com/google/common/util/concurrent/ClosingFuture.java +++ b/android/guava/src/com/google/common/util/concurrent/ClosingFuture.java @@ -32,6 +32,7 @@ import static com.google.common.util.concurrent.Futures.immediateFuture; import static com.google.common.util.concurrent.Futures.nonCancellationPropagating; import static com.google.common.util.concurrent.MoreExecutors.directExecutor; +import static com.google.common.util.concurrent.Platform.restoreInterruptIfIsInterruptedException; import static java.util.logging.Level.FINER; import static java.util.logging.Level.SEVERE; import static java.util.logging.Level.WARNING; @@ -47,7 +48,6 @@ import com.google.errorprone.annotations.DoNotMock; import com.google.j2objc.annotations.RetainedWith; import java.io.Closeable; -import java.io.IOException; import java.util.IdentityHashMap; import java.util.Map; import java.util.concurrent.Callable; @@ -2145,7 +2145,16 @@ private static void closeQuietly(@CheckForNull final Closeable closeable, Execut () -> { try { closeable.close(); - } catch (IOException | RuntimeException e) { + } catch (Exception e) { + /* + * In guava-jre, any kind of Exception may be thrown because `closeable` has type + * `AutoCloseable`. + * + * In guava-android, the only kinds of Exception that may be thrown are + * RuntimeException and IOException because `closeable` has type `Closeable`—except + * that we have to account for sneaky checked exception. + */ + restoreInterruptIfIsInterruptedException(e); logger.log(WARNING, "thrown by close()", e); } }); diff --git a/guava/src/com/google/common/util/concurrent/ClosingFuture.java b/guava/src/com/google/common/util/concurrent/ClosingFuture.java index 16488ab45595..46c5cd187a15 100644 --- a/guava/src/com/google/common/util/concurrent/ClosingFuture.java +++ b/guava/src/com/google/common/util/concurrent/ClosingFuture.java @@ -2159,6 +2159,14 @@ private static void closeQuietly(@CheckForNull final AutoCloseable closeable, Ex try { closeable.close(); } catch (Exception e) { + /* + * In guava-jre, any kind of Exception may be thrown because `closeable` has type + * `AutoCloseable`. + * + * In guava-android, the only kinds of Exception that may be thrown are + * RuntimeException and IOException because `closeable` has type `Closeable`—except + * that we have to account for sneaky checked exception. + */ restoreInterruptIfIsInterruptedException(e); logger.log(WARNING, "thrown by close()", e); }