JAL-4196 make very sure we avoid CME by defensively copying the Map.values() to anoth...
authorJames Procter <j.procter@dundee.ac.uk>
Thu, 8 Jun 2023 10:54:51 +0000 (11:54 +0100)
committerJames Procter <j.procter@dundee.ac.uk>
Thu, 8 Jun 2023 10:54:59 +0000 (11:54 +0100)
src/jalview/workers/AlignCalcManager.java

index d81db8c..fc28e53 100644 (file)
@@ -25,6 +25,7 @@ import jalview.api.AlignCalcWorkerI;
 import jalview.datamodel.AlignmentAnnotation;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Hashtable;
@@ -208,9 +209,18 @@ public class AlignCalcManager implements AlignCalcManagerI
     }
     synchronized (updating)
     {
-      for (List<AlignCalcWorkerI> workers : updating.values())
+      Collection<List<AlignCalcWorkerI>> workersLists = updating.values();
+      synchronized (workersLists)
       {
-        working |= workers.size() > 0;
+        for (List<AlignCalcWorkerI> workers : workersLists)
+        {
+          if (workers!=null)
+          {
+            synchronized (workers) {
+              working |= workers.size() > 0;
+            }
+          }
+        }
       }
     }
     return working;