bugfix for occasional nullpointer exceptions when selecting menu items that operate...
[jalview.git] / src / jalview / datamodel / SequenceGroup.java
index d12f81b..49f270d 100755 (executable)
@@ -691,11 +691,12 @@ public class SequenceGroup
 
   /**
    * 
-   * returns the sequences in the group ordered by the ordering given by al
-   * 
+   * returns the sequences in the group ordered by the ordering given by al.
+   * this used to return an array with null entries regardless, new behaviour is below.
+   * TODO: verify that this does not affect use in applet or application
    * @param al
    *                Alignment
-   * @return SequenceI[]
+   * @return SequenceI[] intersection of sequences in group with al, ordered by al, or null if group does not intersect with al
    */
   public SequenceI[] getSequencesInOrder(AlignmentI al)
   {
@@ -712,7 +713,20 @@ public class SequenceGroup
         seqs[index++] = al.getSequenceAt(i);
       }
     }
-
+    if (index==0)
+    {
+      return null;
+    }
+    if (index<seqs.length)
+    {
+      SequenceI[] dummy = seqs;
+      seqs = new SequenceI[index];
+      while (--index>=0)
+      {
+        seqs[index] = dummy[index];
+        dummy[index] = null;
+      }
+    }
     return seqs;
   }