From: gmungoc Date: Thu, 14 Sep 2017 10:00:07 +0000 (+0100) Subject: JAL-2541 length check in deleteChars (redoing lost commit 4a4bc78) X-Git-Tag: Release_2_11_1_0~98^2~23^2~14 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=043dab77c998532aa84020699d5525832713905d;p=jalview.git JAL-2541 length check in deleteChars (redoing lost commit 4a4bc78) --- diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 80de543..6aaa68b 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -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) { diff --git a/test/jalview/datamodel/SequenceTest.java b/test/jalview/datamodel/SequenceTest.java index cc3c090..5584999 100644 --- a/test/jalview/datamodel/SequenceTest.java +++ b/test/jalview/datamodel/SequenceTest.java @@ -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" })