JAL-2684 JAL-2822 avoid out of bounds exception if edit position is beyond sequence...
authorJim Procter <jprocter@issues.jalview.org>
Tue, 7 Nov 2017 15:58:36 +0000 (15:58 +0000)
committerJim Procter <jprocter@issues.jalview.org>
Tue, 7 Nov 2017 15:58:36 +0000 (15:58 +0000)
src/jalview/commands/EditCommand.java

index d02dbc3..334f30d 100644 (file)
@@ -758,9 +758,14 @@ public class EditCommand implements CommandI
               new String(command.string[i]));
       int ipos = command.seqs[i].findPosition(start)
               - command.seqs[i].getStart();
-      tmp.append(oldstring.substring(end));
+      if (end < oldstring.length())
+      {
+        tmp.append(oldstring.substring(end));
+      }
       command.seqs[i].setSequence(tmp.toString());
-      command.string[i] = oldstring.substring(start, end).toCharArray();
+      command.string[i] = oldstring
+              .substring(start, Math.min(end, oldstring.length()))
+              .toCharArray();
       String nogapold = AlignSeq.extractGaps(Comparison.GapChars,
               new String(command.string[i]));