JAL-1115 refactor base collection for Alignment from Vector to locally synchronized...
[jalview.git] / src / jalview / datamodel / HiddenSequences.java
index 7914d3d..e9f6d1f 100755 (executable)
@@ -175,25 +175,29 @@ public class HiddenSequences
       end = hiddenSequences.length - 1;
     }
 
-    for (int index = end; index > start; index--)
+    List<SequenceI> asequences;
+    synchronized (asequences = alignment.getSequences())
     {
-      SequenceI seq = hiddenSequences[index];
-      hiddenSequences[index] = null;
-
-      if (seq != null)
+      for (int index = end; index > start; index--)
       {
-        if (seq.getLength() > 0)
-        {
-          revealedSeqs.addElement(seq);
-          alignment.getSequences().insertElementAt(seq, alignmentIndex);
-        }
-        else
+        SequenceI seq = hiddenSequences[index];
+        hiddenSequences[index] = null;
+
+        if (seq != null)
         {
-          System.out.println(seq.getName()
-                  + " has been deleted whilst hidden");
+          if (seq.getLength() > 0)
+          {
+            revealedSeqs.addElement(seq);
+            asequences.add(alignmentIndex, seq);
+          }
+          else
+          {
+            System.out.println(seq.getName()
+                    + " has been deleted whilst hidden");
+          }
         }
-      }
 
+      }
     }
 
     return revealedSeqs;