Let StringUtils throw FormatException instead of IllegalArgumentException

This commit is contained in:
Sebastian Kürten
2022-06-29 13:16:37 +02:00
parent ddb759dbb8
commit 4bca9decc1
14 changed files with 91 additions and 52 deletions

View File

@@ -8,6 +8,7 @@ import android.os.StrictMode;
import com.vanniktech.emoji.RecentEmoji;
import org.briarproject.bramble.api.FeatureFlags;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.crypto.CryptoComponent;
import org.briarproject.bramble.api.crypto.KeyStrengthener;
import org.briarproject.bramble.api.crypto.PublicKey;
@@ -242,7 +243,7 @@ public class AppModule {
try {
return crypto.getMessageKeyParser().parsePublicKey(
StringUtils.fromHexString(DEV_PUBLIC_KEY_HEX));
} catch (GeneralSecurityException e) {
} catch (GeneralSecurityException | FormatException e) {
throw new RuntimeException(e);
}
}

View File

@@ -22,6 +22,7 @@ import android.widget.Toast;
import com.google.android.material.snackbar.Snackbar;
import org.briarproject.bramble.api.FeatureFlags;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.Pair;
import org.briarproject.bramble.api.connection.ConnectionRegistry;
import org.briarproject.bramble.api.contact.ContactId;
@@ -519,8 +520,12 @@ public class ConversationActivity extends BriarActivity
Selection<String> selection = tracker.getSelection();
List<MessageId> messages = new ArrayList<>(selection.size());
for (String str : selection) {
MessageId id = new MessageId(fromHexString(str));
messages.add(id);
try {
MessageId id = new MessageId(fromHexString(str));
messages.add(id);
} catch (FormatException e) {
LOG.warning("Invalid message id");
}
}
return messages;
}