Skip to content

Commit

Permalink
Deprecate the remaining two propagateIfPossible overloads.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Mar 6, 2024
1 parent aa1df9f commit cf86414
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions android/guava/src/com/google/common/base/Throwables.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <X extends Throwable> void propagateIfPossible(
Expand All @@ -175,13 +178,14 @@ public static <X extends Throwable> 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}.
*
* <p><b>Discouraged</b> 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 <X1 extends Throwable, X2 extends Throwable> void propagateIfPossible(
Expand Down
10 changes: 7 additions & 3 deletions guava/src/com/google/common/base/Throwables.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <X extends Throwable> void propagateIfPossible(
Expand All @@ -175,13 +178,14 @@ public static <X extends Throwable> 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}.
*
* <p><b>Discouraged</b> 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 <X1 extends Throwable, X2 extends Throwable> void propagateIfPossible(
Expand Down

0 comments on commit cf86414

Please sign in to comment.