From cf86414a87e6e0d008f9438619e97eeefd22a32f Mon Sep 17 00:00:00 2001 From: cpovirk Date: Wed, 6 Mar 2024 07:35:58 -0800 Subject: [PATCH] Deprecate the remaining two `propagateIfPossible` overloads. We'd missed these years ago. They won't be deleted, but we recommend migrating off them: Their behavior is less clear, and we are considering some static analysis that would likely apply to the new methods but not the old. (I notice that there is already [ThrowIfUncheckedKnownChecked](https://errorprone.info/bugpattern/ThrowIfUncheckedKnownChecked). That's a little different, since `propagateIfPossible(knownCheckedException, clazz)` isn't necessarily a no-op. But that could probably would be better written with `throwIfInstanceOf` to make clear that we know we're not rethrowing unchecked exceptions. Anyway, the possible future static analysis includes `throwIfInstanceOf(exception, classThatItCouldNeverBeAnInstanceOf)`, as sometimes seen when accidentally operating on an `ExecutionException` instead of its cause.) RELNOTES=`base`: Deprecated the remaining two overloads of `Throwables.propagateIfPossible`. They won't be deleted, but we recommend migrating off them. PiperOrigin-RevId: 613210259 --- .../guava/src/com/google/common/base/Throwables.java | 10 +++++++--- guava/src/com/google/common/base/Throwables.java | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/android/guava/src/com/google/common/base/Throwables.java b/android/guava/src/com/google/common/base/Throwables.java index 1f1c346e0256..73dad9790a85 100644 --- a/android/guava/src/com/google/common/base/Throwables.java +++ b/android/guava/src/com/google/common/base/Throwables.java @@ -162,7 +162,10 @@ public static void propagateIfPossible(@CheckForNull Throwable throwable) { * * @param throwable the Throwable to possibly propagate * @param declaredType the single checked exception type declared by the calling method + * @deprecated Use a combination of {@link #throwIfInstanceOf} and {@link #throwIfUnchecked}, + * which togther provide the same behavior except that they reject {@code null}. */ + @Deprecated @J2ktIncompatible @GwtIncompatible // propagateIfInstanceOf public static void propagateIfPossible( @@ -175,13 +178,14 @@ public static void propagateIfPossible( * Propagates {@code throwable} exactly as-is, if and only if it is an instance of {@link * RuntimeException}, {@link Error}, {@code declaredType1}, or {@code declaredType2}. * - *

Discouraged in favor of calling {@link #throwIfInstanceOf} and {@link - * #throwIfUnchecked}. - * * @param throwable the Throwable to possibly propagate * @param declaredType1 any checked exception type declared by the calling method * @param declaredType2 any other checked exception type declared by the calling method + * @deprecated Use a combination of two calls to {@link #throwIfInstanceOf} and one call to {@link + * #throwIfUnchecked}, which togther provide the same behavior except that they reject {@code + * null}. */ + @Deprecated @J2ktIncompatible @GwtIncompatible // propagateIfInstanceOf public static void propagateIfPossible( diff --git a/guava/src/com/google/common/base/Throwables.java b/guava/src/com/google/common/base/Throwables.java index 1f1c346e0256..73dad9790a85 100644 --- a/guava/src/com/google/common/base/Throwables.java +++ b/guava/src/com/google/common/base/Throwables.java @@ -162,7 +162,10 @@ public static void propagateIfPossible(@CheckForNull Throwable throwable) { * * @param throwable the Throwable to possibly propagate * @param declaredType the single checked exception type declared by the calling method + * @deprecated Use a combination of {@link #throwIfInstanceOf} and {@link #throwIfUnchecked}, + * which togther provide the same behavior except that they reject {@code null}. */ + @Deprecated @J2ktIncompatible @GwtIncompatible // propagateIfInstanceOf public static void propagateIfPossible( @@ -175,13 +178,14 @@ public static void propagateIfPossible( * Propagates {@code throwable} exactly as-is, if and only if it is an instance of {@link * RuntimeException}, {@link Error}, {@code declaredType1}, or {@code declaredType2}. * - *

Discouraged in favor of calling {@link #throwIfInstanceOf} and {@link - * #throwIfUnchecked}. - * * @param throwable the Throwable to possibly propagate * @param declaredType1 any checked exception type declared by the calling method * @param declaredType2 any other checked exception type declared by the calling method + * @deprecated Use a combination of two calls to {@link #throwIfInstanceOf} and one call to {@link + * #throwIfUnchecked}, which togther provide the same behavior except that they reject {@code + * null}. */ + @Deprecated @J2ktIncompatible @GwtIncompatible // propagateIfInstanceOf public static void propagateIfPossible(