summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2018-01-08 04:31:30 -0600
committerSamuel Holland <samuel@sholland.org>2018-01-08 04:31:30 -0600
commitdcbcc62b6497c1c6fd69431301c8dc1fa7dd7d9c (patch)
tree115d4a0b133f24bffd2d77d26f78aacc6d2e823d /app/src/main/java/com/wireguard
parentfbc1729f162c9e6197c186a6f19cbd05a184663a (diff)
TunnelListFragment: Fix crash on deleting multiple tunnels
Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'app/src/main/java/com/wireguard')
-rw-r--r--app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java9
1 files changed, 8 insertions, 1 deletions
diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java
index 0a374555..eb5b6af1 100644
--- a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java
+++ b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java
@@ -38,10 +38,14 @@ import com.wireguard.android.util.AsyncWorker;
import com.wireguard.android.util.ExceptionLoggers;
import com.wireguard.config.Config;
+import java.util.List;
+
import java9.util.concurrent.CompletableFuture;
import java9.util.concurrent.CompletionStage;
import java9.util.function.Function;
+import java9.util.stream.Collectors;
import java9.util.stream.IntStream;
+import java9.util.stream.StreamSupport;
/**
* Fragment containing a list of known WireGuard tunnels. It allows creating and deleting tunnels.
@@ -194,8 +198,11 @@ public class TunnelListFragment extends BaseFragment {
public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_action_delete:
- final CompletableFuture[] futures = getCheckedPositions()
+ // Must operate in two steps: positions change once we start deleting things.
+ final List<Tunnel> tunnelsToDelete = getCheckedPositions()
.mapToObj(pos -> (Tunnel) tunnelList.getItemAtPosition(pos))
+ .collect(Collectors.toList());
+ final CompletableFuture[] futures = StreamSupport.stream(tunnelsToDelete)
.map(Tunnel::delete)
.toArray(CompletableFuture[]::new);
CompletableFuture.allOf(futures)