refactor(sonar): replace if/throw with require/error

Sonar — replace hand-rolled 'throw IllegalArgumentException' / 'throw
IllegalStateException' with the idiomatic 'require { msg }' / 'error(msg)'.
Exception types preserved exactly (require throws IAE, error throws ISE).
This commit is contained in:
davotoula
2026-05-13 10:17:13 +02:00
parent 6960bdf497
commit 5e179326d4
4 changed files with 6 additions and 8 deletions
@@ -200,9 +200,7 @@ class OwnedEmojiPacksState(
isPrivate: Boolean,
account: Account,
) {
if (!EmojiUrlTag.isValidShortcode(emojiTag.code)) {
throw IllegalArgumentException("Invalid emoji shortcode: ${emojiTag.code}")
}
require(EmojiUrlTag.isValidShortcode(emojiTag.code)) { "Invalid emoji shortcode: ${emojiTag.code}" }
val packEvent = getOwnedEmojiPackEvent(dTag) ?: return
@@ -52,7 +52,7 @@ tailrec fun Context.getActivity(): ComponentActivity =
when (this) {
is ComponentActivity -> this
is ContextWrapper -> baseContext.getActivity()
else -> throw IllegalStateException("Requires a ComponentActivity to run")
else -> error("Requires a ComponentActivity to run")
}
fun Context.getActivityOrNull(): ComponentActivity? =