From c59fc3581a14dbe1519054d674e04765b2360c81 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Mon, 4 May 2020 00:48:09 -0400 Subject: [PATCH] Make LiveRecipientCache throw exceptions instead of errors. Errors were causing crash loops if they occur in a job. This will still allow the app to crash, but prevent loops. --- .../securesms/database/RecipientDatabase.java | 6 +++--- .../securesms/recipients/LiveRecipientCache.java | 12 +++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java index 8bda02cdd..4c4a120b7 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java @@ -400,7 +400,7 @@ public class RecipientDatabase extends Database { if (cursor != null && cursor.moveToNext()) { return getRecipientSettings(context, cursor); } else { - throw new MissingRecipientError(id); + throw new MissingRecipientException(id); } } } @@ -1928,8 +1928,8 @@ public class RecipientDatabase extends Database { } } - public static class MissingRecipientError extends AssertionError { - public MissingRecipientError(@Nullable RecipientId id) { + public static class MissingRecipientException extends IllegalStateException { + public MissingRecipientException(@Nullable RecipientId id) { super("Failed to find recipient with ID: " + id); } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java index 15a5fc40f..7040d3994 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java +++ b/app/src/main/java/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java @@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.recipients; import android.annotation.SuppressLint; import android.content.Context; -import android.text.TextUtils; import androidx.annotation.AnyThread; import androidx.annotation.NonNull; @@ -12,14 +11,13 @@ import com.annimon.stream.Stream; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.RecipientDatabase; -import org.thoughtcrime.securesms.database.RecipientDatabase.MissingRecipientError; +import org.thoughtcrime.securesms.database.RecipientDatabase.MissingRecipientException; import org.thoughtcrime.securesms.database.ThreadDatabase; import org.thoughtcrime.securesms.database.model.ThreadRecord; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.util.LRUCache; import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.concurrent.SignalExecutors; -import org.whispersystems.libsignal.util.guava.Optional; import java.util.ArrayList; import java.util.Collections; @@ -61,12 +59,12 @@ public final class LiveRecipientCache { recipients.put(id, newLive); - MissingRecipientError prettyStackTraceError = new MissingRecipientError(newLive.getId()); + MissingRecipientException prettyStackTraceError = new MissingRecipientException(newLive.getId()); SignalExecutors.BOUNDED.execute(() -> { try { newLive.resolve(); - } catch (MissingRecipientError e) { + } catch (MissingRecipientException e) { throw prettyStackTraceError; } }); @@ -88,11 +86,11 @@ public final class LiveRecipientCache { } else if (localE164 != null) { localRecipientId = recipientDatabase.getByE164(localE164).orNull(); } else { - throw new AssertionError("Tried to call getSelf() before local data was set!"); + throw new IllegalStateException("Tried to call getSelf() before local data was set!"); } if (localRecipientId == null) { - throw new MissingRecipientError(localRecipientId); + throw new MissingRecipientException(localRecipientId); } } }