[network/kdeconnect-android] src/main/java/org/kde/kdeconnect/ui: Fixed OOB access if interacting with devices mid-removal

Albert Vaca Cintora <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 884781662a03ef81bdb64e0d7eb83965a64b0573 by Albert Vaca Cintora.
Committed on 07/08/2026 at 09:14.
Pushed by albertvaka into branch 'master'.

Fixed OOB access if interacting with devices mid-removal

M  +11   -2    src/main/java/org/kde/kdeconnect/ui/CustomDevicesAdapter.java

https://invent.kde.org/network/kdeconnect-android/-/commit/884781662a03ef81bdb64e0d7eb83965a64b0573

diff --git a/src/main/java/org/kde/kdeconnect/ui/CustomDevicesAdapter.java b/src/main/java/org/kde/kdeconnect/ui/CustomDevicesAdapter.java
index 690ebddc4..6e645eb9c 100644
--- a/src/main/java/org/kde/kdeconnect/ui/CustomDevicesAdapter.java
+++ b/src/main/java/org/kde/kdeconnect/ui/CustomDevicesAdapter.java
@@ -46,7 +46,11 @@ public class CustomDevicesAdapter extends RecyclerView.Adapter<CustomDevicesAdap
         super.onAttachedToRecyclerView(recyclerView);
 
         ItemTouchHelper itemTouchHelper = new ItemTouchHelper(
-                new ItemTouchHelperCallback(adapterPos -> callback.onCustomDeviceDismissed(customDevices.get(adapterPos))));
+                new ItemTouchHelperCallback(adapterPos -> {
+                    if (adapterPos != RecyclerView.NO_POSITION) {
+                        callback.onCustomDeviceDismissed(customDevices.get(adapterPos));
+                    }
+                }));
         itemTouchHelper.attachToRecyclerView(recyclerView);
     }
 
@@ -77,7 +81,12 @@ public class CustomDevicesAdapter extends RecyclerView.Adapter<CustomDevicesAdap
         ViewHolder(@NonNull CustomDeviceItemBinding itemBinding, Context context) {
             super(itemBinding.getRoot());
             this.itemBinding = itemBinding;
-            itemBinding.deviceNameOrIP.setOnClickListener(v -> callback.onCustomDeviceClicked(customDevices.get(getAbsoluteAdapterPosition())));
+            itemBinding.deviceNameOrIP.setOnClickListener(v -> {
+                int position = getAbsoluteAdapterPosition();
+                if (position != RecyclerView.NO_POSITION) {
+                    callback.onCustomDeviceClicked(customDevices.get(position));
+                }
+            });
             this.context = context;
         }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.