From 043dab77c998532aa84020699d5525832713905d Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 14 Sep 2017 11:00:07 +0100 Subject: [PATCH] JAL-2541 length check in deleteChars (redoing lost commit 4a4bc78) --- src/jalview/datamodel/Sequence.java | 4 ++-- test/jalview/datamodel/SequenceTest.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) 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" }) -- 1.7.10.2