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.
This commit is contained in:
Greyson Parrelli 2020-05-04 00:48:09 -04:00
parent e00f8c94ff
commit c59fc3581a
2 changed files with 8 additions and 10 deletions

View File

@ -400,7 +400,7 @@ public class RecipientDatabase extends Database {
if (cursor != null && cursor.moveToNext()) { if (cursor != null && cursor.moveToNext()) {
return getRecipientSettings(context, cursor); return getRecipientSettings(context, cursor);
} else { } 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 static class MissingRecipientException extends IllegalStateException {
public MissingRecipientError(@Nullable RecipientId id) { public MissingRecipientException(@Nullable RecipientId id) {
super("Failed to find recipient with ID: " + id); super("Failed to find recipient with ID: " + id);
} }
} }

View File

@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.recipients;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.text.TextUtils;
import androidx.annotation.AnyThread; import androidx.annotation.AnyThread;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -12,14 +11,13 @@ import com.annimon.stream.Stream;
import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.RecipientDatabase; 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.ThreadDatabase;
import org.thoughtcrime.securesms.database.model.ThreadRecord; import org.thoughtcrime.securesms.database.model.ThreadRecord;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.util.LRUCache; import org.thoughtcrime.securesms.util.LRUCache;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.concurrent.SignalExecutors; import org.thoughtcrime.securesms.util.concurrent.SignalExecutors;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -61,12 +59,12 @@ public final class LiveRecipientCache {
recipients.put(id, newLive); recipients.put(id, newLive);
MissingRecipientError prettyStackTraceError = new MissingRecipientError(newLive.getId()); MissingRecipientException prettyStackTraceError = new MissingRecipientException(newLive.getId());
SignalExecutors.BOUNDED.execute(() -> { SignalExecutors.BOUNDED.execute(() -> {
try { try {
newLive.resolve(); newLive.resolve();
} catch (MissingRecipientError e) { } catch (MissingRecipientException e) {
throw prettyStackTraceError; throw prettyStackTraceError;
} }
}); });
@ -88,11 +86,11 @@ public final class LiveRecipientCache {
} else if (localE164 != null) { } else if (localE164 != null) {
localRecipientId = recipientDatabase.getByE164(localE164).orNull(); localRecipientId = recipientDatabase.getByE164(localE164).orNull();
} else { } 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) { if (localRecipientId == null) {
throw new MissingRecipientError(localRecipientId); throw new MissingRecipientException(localRecipientId);
} }
} }
} }