From b1b97b8b45fc77b0ebaedff51f61bb30c8451343 Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Tue, 5 Nov 2019 15:32:35 -0800 Subject: [PATCH] UiThreadUtil.assertX should only throw in DEBUG mode Summary: Turns out that `SoftAssertions.java` has always been a lie - it actually always throws exceptions. Migrate it to using `ReactSoftException`. This file hasn't been touched at all since it was originally open-sourced, besides codemods! Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D18336020 fbshipit-source-id: cba3db25a9f9d61325dd3f7843e92e984ae56281 --- .../facebook/react/bridge/SoftAssertions.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/SoftAssertions.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/SoftAssertions.java index 409b48eb4f8..434ad411ad1 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/SoftAssertions.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/SoftAssertions.java @@ -20,26 +20,32 @@ public class SoftAssertions { /** * Throw {@link AssertionException} with a given message. Use this method surrounded with {@code * if} block with assert condition in case you plan to do string concatenation to produce the - * message. + * message. This logs an assertion with ReactSoftException, which decides whether or not to + * actually throw. */ public static void assertUnreachable(String message) { - throw new AssertionException(message); + ReactSoftException.logSoftException("SoftAssertions", new AssertionException(message)); } /** * Asserts the given condition, throwing an {@link AssertionException} if the condition doesn't - * hold. + * hold. This logs an assertion with ReactSoftException, which decides whether or not to actually + * throw. */ public static void assertCondition(boolean condition, String message) { if (!condition) { - throw new AssertionException(message); + ReactSoftException.logSoftException("SoftAssertions", new AssertionException(message)); } } - /** Asserts that the given Object isn't null, throwing an {@link AssertionException} if it was. */ + /** + * Asserts that the given Object isn't null, throwing an {@link AssertionException} if it was. + * This logs an assertion with ReactSoftException, which decides whether or not to actually throw. + */ public static T assertNotNull(@Nullable T instance) { if (instance == null) { - throw new AssertionException("Expected object to not be null!"); + ReactSoftException.logSoftException( + "SoftAssertions", new AssertionException("Expected object to not be null!")); } return instance; }