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.
fork-5.53.8
Greyson Parrelli 2020-05-04 00:48:09 -04:00
rodzic e00f8c94ff
commit c59fc3581a
2 zmienionych plików z 8 dodań i 10 usunięć

Wyświetl plik

@ -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);
}
}

Wyświetl plik

@ -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);
}
}
}