Merge branch 'bug/JAL-4313-make-visible-annot-fix' into JAL-1601-direct-jpred4-rest...
[jalview.git] / src / jalview / datamodel / AlignmentAnnotation.java
index 0e0239a..fdb62a1 100755 (executable)
@@ -854,15 +854,15 @@ public class AlignmentAnnotation
     }
     if (startRes >= annotations.length)
     {
-      startRes = annotations.length - 1;
+      startRes = annotations.length;
     }
-    if (endRes >= annotations.length)
+    if (endRes < 0)
     {
-      endRes = annotations.length - 1;
+      endRes = -1;
     }
-    if (annotations == null)
+    if (endRes >= annotations.length)
     {
-      return;
+      endRes = annotations.length - 1;
     }
     Annotation[] temp = new Annotation[endRes - startRes + 1];
     if (startRes < annotations.length)
@@ -1625,6 +1625,8 @@ public class AlignmentAnnotation
   private void removeHiddenAnnotation(int start, int end,
           HiddenColumns hiddenColumns)
   {
+    start = Math.min(Math.max(0, start), annotations.length);
+    end = Math.min(Math.max(-1, end), annotations.length - 1);
     // mangle the alignmentAnnotation annotation array
     ArrayList<Annotation[]> annels = new ArrayList<>();
     Annotation[] els = null;