From 9ca6253f8dc472a6147f55fd928b433d1de804cf Mon Sep 17 00:00:00 2001 From: cyBerta Date: Tue, 11 Dec 2018 08:40:46 +0100 Subject: fix concurrent modification exception in vpn status --- .../java/de/blinkt/openvpn/core/VpnStatus.java | 27 ++++++++-------------- 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/de/blinkt/openvpn/core/VpnStatus.java b/app/src/main/java/de/blinkt/openvpn/core/VpnStatus.java index e7576bb5..0fae6183 100644 --- a/app/src/main/java/de/blinkt/openvpn/core/VpnStatus.java +++ b/app/src/main/java/de/blinkt/openvpn/core/VpnStatus.java @@ -15,12 +15,10 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.util.LinkedList; import java.util.Locale; -import java.util.Queue; import java.util.Vector; -import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.CopyOnWriteArrayList; import se.leap.bitmaskclient.R; -import de.blinkt.openvpn.VpnProfile; public class VpnStatus { @@ -28,7 +26,7 @@ public class VpnStatus { private static final LinkedList logbuffer; private static Vector logListener; - private static Vector stateListener; + private static CopyOnWriteArrayList stateListener; private static Vector byteCountListener; private static String mLaststatemsg = ""; @@ -200,7 +198,7 @@ public class VpnStatus { static { logbuffer = new LinkedList<>(); logListener = new Vector<>(); - stateListener = new Vector<>(); + stateListener = new CopyOnWriteArrayList<>(); byteCountListener = new Vector<>(); trafficHistory = new TrafficHistory(); @@ -268,12 +266,10 @@ public class VpnStatus { public synchronized static void addStateListener(StateListener sl) { - synchronized (stateListener) { - if (!stateListener.contains(sl)) { - stateListener.add(sl); - if (mLaststate != null) + if (!stateListener.contains(sl)) { + stateListener.add(sl); + if (mLaststate != null) sl.updateState(mLaststate, mLaststatemsg, mLastStateresid, mLastLevel); - } } } @@ -354,9 +350,7 @@ public class VpnStatus { public synchronized static void removeStateListener(StateListener sl) { - synchronized (stateListener) { - stateListener.remove(sl); - } + stateListener.remove(sl); } @@ -388,11 +382,8 @@ public class VpnStatus { mLastStateresid = resid; mLastLevel = level; - - synchronized (stateListener) { - for (StateListener sl : stateListener) { - sl.updateState(state, msg, resid, level); - } + for (StateListener sl : stateListener) { + sl.updateState(state, msg, resid, level); } //newLogItem(new LogItem((LogLevel.DEBUG), String.format("New OpenVPN Status (%s->%s): %s",state,level.toString(),msg))); } -- cgit v1.2.3