From: gmungoc Date: Wed, 5 Jul 2017 12:37:26 +0000 (+0100) Subject: JAL-147 additions to unit test, check for negative array index X-Git-Tag: Release_2_10_3b1~132^2~47 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=1dcf7a8a1ab8fd8fb5259c0aaca2a6c73ed056ad;p=jalview.git JAL-147 additions to unit test, check for negative array index --- diff --git a/src/jalview/datamodel/HiddenSequences.java b/src/jalview/datamodel/HiddenSequences.java index a57dc9c..98e9694 100755 --- a/src/jalview/datamodel/HiddenSequences.java +++ b/src/jalview/datamodel/HiddenSequences.java @@ -157,9 +157,10 @@ public class HiddenSequences int absAlignmentIndex = alignment.findIndex(sequence); int alignmentIndex = adjustForHiddenSeqs(absAlignmentIndex); - if (hiddenSequences[alignmentIndex] != null) + if (alignmentIndex < 0 || hiddenSequences[alignmentIndex] != null) { System.out.println("ERROR!!!!!!!!!!!"); + return; } hiddenSequences[alignmentIndex] = sequence; diff --git a/test/jalview/datamodel/HiddenSequencesTest.java b/test/jalview/datamodel/HiddenSequencesTest.java index 5b2bbd4..11b993d 100644 --- a/test/jalview/datamodel/HiddenSequencesTest.java +++ b/test/jalview/datamodel/HiddenSequencesTest.java @@ -208,15 +208,17 @@ public class HiddenSequencesTest assertEquals(6, hs.findIndexWithoutHiddenSeqs(9)); /* - * hide first sequence only + * hide first two sequences */ hs.showAll(null); hs.hideSequence(seqs[0]); - for (int i = 1; i < height; i++) + hs.hideSequence(seqs[1]); + assertEquals(-1, hs.findIndexWithoutHiddenSeqs(0)); + assertEquals(-1, hs.findIndexWithoutHiddenSeqs(1)); + for (int i = 2; i < height; i++) { - assertEquals(i - 1, hs.findIndexWithoutHiddenSeqs(i)); + assertEquals(i - 2, hs.findIndexWithoutHiddenSeqs(i)); } - assertEquals(-1, hs.findIndexWithoutHiddenSeqs(0)); } /**