From 2f512705e833170cbe8afa742c2fdd8349d1acf7 Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Thu, 27 Apr 2023 12:59:32 +0200 Subject: [PATCH] Fix IndexOutOfBoundsException in onPause (#3581) Use `getOrNull` instead of `get`, which was occasionally throwing IndexOutOfBoundsException. --- .../tusky/components/notifications/NotificationsFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsFragment.kt b/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsFragment.kt index 49267b5f..8bc17e27 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsFragment.kt @@ -453,7 +453,7 @@ class NotificationsFragment : // Save the ID of the first notification visible in the list val position = layoutManager.findFirstVisibleItemPosition() if (position >= 0) { - adapter.snapshot()[position]?.id?.let { id -> + adapter.snapshot().getOrNull(position)?.id?.let { id -> viewModel.accept(InfallibleUiAction.SaveVisibleId(visibleId = id)) } }