JAL-2541 length check in deleteChars (redoing lost commit 4a4bc78)
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 14 Sep 2017 10:00:07 +0000 (11:00 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 14 Sep 2017 10:00:07 +0000 (11:00 +0100)
src/jalview/datamodel/Sequence.java
test/jalview/datamodel/SequenceTest.java

index 80de543..6aaa68b 100755 (executable)
@@ -1159,9 +1159,9 @@ public class Sequence extends ASequence implements SequenceI
     // the very large sequence case
     int eindex = -1, sindex = -1;
     boolean ecalc = false, scalc = false;
-    for (int s = i; s < j; s++)
+    for (int s = i; s < j && s < sequence.length; s++)
     {
-      if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
+      if (!Comparison.isGap(sequence[s]))
       {
         if (createNewDs)
         {
index cc3c090..5584999 100644 (file)
@@ -548,6 +548,21 @@ public class SequenceTest
     assertEquals(1, sq.getStart());
     assertEquals(4, sq.getEnd());
     assertNull(PA.getValue(sq, "datasetSequence"));
+
+    /*
+     * delete more positions than there are
+     */
+    sq = new Sequence("test/8-11", "ABCD");
+    sq.deleteChars(0, 99);
+    assertEquals("", sq.getSequenceAsString());
+    assertEquals(12, sq.getStart()); // = findPosition(99) ?!?
+    assertEquals(11, sq.getEnd());
+
+    sq = new Sequence("test/8-11", "----");
+    sq.deleteChars(0, 99); // ArrayIndexOutOfBoundsException <= 2.10.2
+    assertEquals("", sq.getSequenceAsString());
+    assertEquals(8, sq.getStart());
+    assertEquals(11, sq.getEnd());
   }
 
   @Test(groups = { "Functional" })