Skip to content

Commit cfbd282

Browse files
committed
[Win32] Thread-safe modification of Edge instances
The WebView environment used for Edge manages a list of all currently used Edge instances inside an application. This data structure is modified at different places, which may be executed by different threads, such introducing a risk of race conditions on the unsynchronized data structure. In addition, when disposing a Display (such as at application shutdown), Edge instances are disposed in an according dispose listener. This can cause ConcurrentModificationExceptions as the listener iterates through the list of Edge instances and calls their disposal, which in turn removes the Edge instance from that list. This change makes the data structure thread-safe and copy-on-write to avoid that ConcurrentModificationException occur when iterating over it while removing elements from it.
1 parent b0a1fb7 commit cfbd282

File tree

1 file changed

+3
-2
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser

1 file changed

+3
-2
lines changed

bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.nio.file.Path;
2121
import java.time.*;
2222
import java.util.*;
23+
import java.util.List;
2324
import java.util.concurrent.*;
2425
import java.util.concurrent.atomic.*;
2526
import java.util.function.*;
@@ -62,9 +63,9 @@ class Edge extends WebBrowser {
6263
private static final int MAXIMUM_CREATION_RETRIES = 5;
6364
private static final Duration MAXIMUM_OPERATION_TIME = Duration.ofMillis(Integer.getInteger(WEB_VIEW_OPERATION_TIMEOUT, 5_000));
6465

65-
private record WebViewEnvironment(ICoreWebView2Environment environment, ArrayList<Edge> instances) {
66+
private record WebViewEnvironment(ICoreWebView2Environment environment, List<Edge> instances) {
6667
public WebViewEnvironment(ICoreWebView2Environment environment) {
67-
this (environment, new ArrayList<>());
68+
this (environment, new CopyOnWriteArrayList<>());
6869
}
6970
}
7071

0 commit comments

Comments
 (0)