JAL-3858 JAL-4090 avoid NPE when given out of bound column ranges when requesting...
authorJames Procter <j.procter@dundee.ac.uk>
Tue, 26 Sep 2023 10:59:08 +0000 (11:59 +0100)
committerJames Procter <j.procter@dundee.ac.uk>
Tue, 26 Sep 2023 10:59:08 +0000 (11:59 +0100)
src/jalview/datamodel/Alignment.java
test/jalview/datamodel/PAEContactMatrixTest.java

index 514a326..aef2038 100755 (executable)
@@ -2069,6 +2069,10 @@ public class Alignment implements AlignmentI, AutoCloseable
   @Override
   public ContactListI getContactListFor(AlignmentAnnotation _aa, int column)
   {
+    if (_aa.annotations==null || column>=_aa.annotations.length || column<0)
+    {
+      return null;
+    }
     ContactListI cl = cmholder.getContactListFor(_aa, column);
     if (cl == null && _aa.groupRef != null)
     {
index bdfa5a3..fa7aca5 100644 (file)
@@ -116,7 +116,11 @@ public class PAEContactMatrixTest
     AlignmentI alForSeq = new Alignment(new SequenceI[] { alseq });
     newaa = AlignmentUtils.addReferenceAnnotationTo(alForSeq, alseq, newaa,
             null);
-    ContactListI alcl = alForSeq.getContactListFor(newaa, 1);
+    // check for null on out of bounds
+    ContactListI alcl = alForSeq.getContactListFor(newaa, newaa.annotations.length);
+    assertNull(alcl,"Should've gotten null!");
+    // now check for mapping
+    alcl = alForSeq.getContactListFor(newaa, 1);
     assertNotNull(alcl);
     mappedCl = alcl.getMappedPositionsFor(0, 4);
     assertNotNull(mappedCl);