]> git.ktnx.net Git - mobile-ledger.git/commitdiff
guard against a race condition when the transaction list is reduced while the scrolle...
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 21 Dec 2018 20:29:14 +0000 (20:29 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 21 Dec 2018 20:29:14 +0000 (20:29 +0000)
app/src/main/java/net/ktnx/mobileledger/TransactionListAdapter.java

index e69aab7bf44ffaf728e226cefd265740a7986a8d..559a247beb3b495223d5d68921a3c6e57ecb9fd8 100644 (file)
@@ -48,6 +48,12 @@ class TransactionListAdapter
     }
 
     public void onBindViewHolder(@NonNull TransactionRowHolder holder, int position) {
+        // in a race when transaction list is reduced, but the model hasn't been notified yet
+        // the view will disappear when the notifications reaches the model, so by simply omitting
+        // the out-of-range get() call nothing bad happens - just a to-be-deleted view remains
+        // a bit longer
+        if (position >= transactions.size()) return;
+
         LedgerTransaction tr = transactions.get(position);
         Context ctx = holder.row.getContext();