mbien commented on code in PR #7610:
URL: https://github.com/apache/netbeans/pull/7610#discussion_r1702851353
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/singlesourcefile/SingleFileOptionsQueryImpl.java:
##########
@@ -60,13 +61,36 @@ public Result optionsFor(FileObject file) {
workspaces = workspace2Settings.keySet();
}
- for (Workspace w : workspaces) {
- FileObject folder = findWorkspaceFolder(w, file);
- if (folder != null) {
- return getResult(w, folder);
+ int count = 0;
+ try {
+ for (Workspace w : workspaces) {
+ if (w == null)
+ continue; // Since a WeakHashMap is in use, it
is possible to receive a null value.
+ FileObject folder = findWorkspaceFolder(w, file);
+ if (folder != null) {
+ return getResult(w, folder);
+ }
+ if (count++ == 0 && workspace == null)
+ workspace = w;
}
+ } catch (ConcurrentModificationException ignore) {
+ // In the rare event that a concurrent invocation of this
method caused the Map to change,
+ // at least avoid an unexpected exception for the invoker.
}
Review Comment:
please don't do this. L60 has already a critical section. You could create a
local copy of the Set there.
```java
List<Workspace> workspaces;
...
//L61
workspaces = new ArrayList<>(workspace2Settings.keySet());
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists