Skip to content

Commit

Permalink
Make the backport's ClosingFuture catch any Exception, even thoug…
Browse files Browse the repository at this point in the history
…h 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
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Dec 11, 2023
1 parent 314953c commit b2baf48
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit b2baf48

Please sign in to comment.