Program: 149600
Project: 149600
Buggy source:
public static BandedSemiLocalResult semiLocalRight0(final AffineGapAlignmentScoring<NucleotideSequence> scoring,final NucleotideSequence seq1,final NucleotideSequence seq2,final int offset1,int length1,final int offset2,int length2,final int width,final MutationsBuilder<NucleotideSequence> mutations,final MatrixCache cache){
  if (length1 == 0 || length2 == 0)   return new BandedSemiLocalResult(offset1 - 1,offset2 - 1,0);
  int minLength=Math.min(length1,length2) + width;
  length1=Math.min(length1,minLength);
  length2=Math.min(length2,minLength);
  int size1=length1 + 1, size2=length2 + 1;
  cache.prepareMatrices(size1,size2,width,scoring);
  BandedMatrix main=cache.main;
  BandedMatrix gapIn1=cache.gapIn1;
  BandedMatrix gapIn2=cache.gapIn2;
  int i, j;
  int match, gap1, gap2, to;
  int maxI=0, maxJ=0, maxScore=Integer.MIN_VALUE;
  final int gapExtensionPenalty=scoring.getGapExtensionPenalty();
  for (i=0; i < length1; ++i) {
    to=Math.min(i + main.getRowFactor() - main.getColumnDelta() + 1,length2);
    for (j=Math.max(0,i - main.getColumnDelta()); j < to; ++j) {
      match=main.get(i,j) + scoring.getScore(seq1.codeAt(offset1 + i),seq2.codeAt(offset2 + j));
      gap1=Math.max(main.get(i + 1,j) + scoring.getGapOpenPenalty(),gapIn1.get(i + 1,j) + gapExtensionPenalty);
      gap2=Math.max(main.get(i,j + 1) + scoring.getGapOpenPenalty(),gapIn2.get(i,j + 1) + gapExtensionPenalty);
      gapIn1.set(i + 1,j + 1,gap1);
      gapIn2.set(i + 1,j + 1,gap2);
      int score=Math.max(match,Math.max(gap1,gap2));
      main.set(i + 1,j + 1,score);
      if (score > maxScore) {
        maxScore=score;
        maxI=i;
        maxJ=j;
      }
    }
  }
  to=mutations.size();
  i=maxI;
  j=maxJ;
  int pScore=main.get(i + 1,j + 1);
  byte c1, c2;
  while (i >= 0 || j >= 0) {
    if (i >= 0 && pScore == gapIn2.get(i + 1,j + 1)) {
      if (pScore == gapIn2.get(i,j + 1) + gapExtensionPenalty)       pScore=gapIn2.get(i,j + 1);
 else       pScore=main.get(i,j + 1);
      mutations.appendDeletion(offset1 + i,seq1.codeAt(offset1 + i));
      --i;
    }
 else     if (j >= 0 && pScore == gapIn1.get(i + 1,j + 1)) {
      if (pScore == gapIn1.get(i + 1,j) + gapExtensionPenalty)       pScore=gapIn1.get(i + 1,j);
 else       pScore=main.get(i + 1,j);
      mutations.appendInsertion(offset1 + i + 1,seq2.codeAt(offset2 + j));
      --j;
    }
 else     if (i >= 0 && j >= 0 && pScore == main.get(i,j) + scoring.getScore(c1=seq1.codeAt(offset1 + i),c2=seq2.codeAt(offset2 + j))) {
      pScore=main.get(i,j);
      if (c1 != c2)       mutations.appendSubstitution(offset1 + i,c1,c2);
      --i;
      --j;
    }
 else     throw new RuntimeException();
  }
  mutations.reverseRange(to,mutations.size());
  return new BandedSemiLocalResult(offset1 + maxI,offset2 + maxJ,maxScore);
}

Fixed version (ground truth):
public static BandedSemiLocalResult semiLocalRight0(final AffineGapAlignmentScoring<NucleotideSequence> scoring,final NucleotideSequence seq1,final NucleotideSequence seq2,final int offset1,int length1,final int offset2,int length2,final int width,final MutationsBuilder<NucleotideSequence> mutations,final MatrixCache cache){
  if (length1 == 0 || length2 == 0)   return new BandedSemiLocalResult(offset1 - 1,offset2 - 1,0);
  int minLength=Math.min(length1,length2) + width;
  length1=Math.min(length1,minLength);
  length2=Math.min(length2,minLength);
  int size1=length1 + 1, size2=length2 + 1;
  cache.prepareMatrices(size1,size2,width,scoring);
  BandedMatrix main=cache.main;
  BandedMatrix gapIn1=cache.gapIn1;
  BandedMatrix gapIn2=cache.gapIn2;
  int i, j;
  int match, gap1, gap2, to;
  int maxI=-1, maxJ=-1, maxScore=0;
  final int gapExtensionPenalty=scoring.getGapExtensionPenalty();
  for (i=0; i < length1; ++i) {
    to=Math.min(i + main.getRowFactor() - main.getColumnDelta() + 1,length2);
    for (j=Math.max(0,i - main.getColumnDelta()); j < to; ++j) {
      match=main.get(i,j) + scoring.getScore(seq1.codeAt(offset1 + i),seq2.codeAt(offset2 + j));
      gap1=Math.max(main.get(i + 1,j) + scoring.getGapOpenPenalty(),gapIn1.get(i + 1,j) + gapExtensionPenalty);
      gap2=Math.max(main.get(i,j + 1) + scoring.getGapOpenPenalty(),gapIn2.get(i,j + 1) + gapExtensionPenalty);
      gapIn1.set(i + 1,j + 1,gap1);
      gapIn2.set(i + 1,j + 1,gap2);
      int score=Math.max(match,Math.max(gap1,gap2));
      main.set(i + 1,j + 1,score);
      if (score > maxScore) {
        maxScore=score;
        maxI=i;
        maxJ=j;
      }
    }
  }
  to=mutations.size();
  i=maxI;
  j=maxJ;
  int pScore=main.get(i + 1,j + 1);
  byte c1, c2;
  while (i >= 0 || j >= 0) {
    if (i >= 0 && pScore == gapIn2.get(i + 1,j + 1)) {
      if (pScore == gapIn2.get(i,j + 1) + gapExtensionPenalty)       pScore=gapIn2.get(i,j + 1);
 else       pScore=main.get(i,j + 1);
      mutations.appendDeletion(offset1 + i,seq1.codeAt(offset1 + i));
      --i;
    }
 else     if (j >= 0 && pScore == gapIn1.get(i + 1,j + 1)) {
      if (pScore == gapIn1.get(i + 1,j) + gapExtensionPenalty)       pScore=gapIn1.get(i + 1,j);
 else       pScore=main.get(i + 1,j);
      mutations.appendInsertion(offset1 + i + 1,seq2.codeAt(offset2 + j));
      --j;
    }
 else     if (i >= 0 && j >= 0 && pScore == main.get(i,j) + scoring.getScore(c1=seq1.codeAt(offset1 + i),c2=seq2.codeAt(offset2 + j))) {
      pScore=main.get(i,j);
      if (c1 != c2)       mutations.appendSubstitution(offset1 + i,c1,c2);
      --i;
      --j;
    }
 else     throw new RuntimeException();
  }
  mutations.reverseRange(to,mutations.size());
  return new BandedSemiLocalResult(offset1 + maxI,offset2 + maxJ,maxScore);
}