Program: 149599
Project: 149599
Buggy source:
public static BandedSemiLocalResult semiLocalLeft0(final AffineGapAlignmentScoring<NucleotideSequence> scoring,final NucleotideSequence seq1,final NucleotideSequence seq2,int offset1,int length1,int offset2,int length2,final int width,final MutationsBuilder<NucleotideSequence> mutations,final MatrixCache cache){
  if (length1 == 0 || length2 == 0)   return new BandedSemiLocalResult(offset1 + length1,offset2 + length2,0);
  offset1+=length1;
  offset2+=length2;
  int minLength=Math.min(length1,length2) + width;
  length1=Math.min(length1,minLength);
  length2=Math.min(length2,minLength);
  offset1-=length1;
  offset2-=length2;
  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 + length1 - 1 - i),seq2.codeAt(offset2 + length2 - 1 - 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;
      }
    }
  }
  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 + length1 - 1 - i,seq1.codeAt(offset1 + length1 - 1 - 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 + length1 - 1 - i,seq2.codeAt(offset2 + length2 - 1 - j));
      --j;
    }
 else     if (i >= 0 && j >= 0 && pScore == main.get(i,j) + scoring.getScore(c1=seq1.codeAt(offset1 + length1 - 1 - i),c2=seq2.codeAt(offset2 + length2 - 1 - j))) {
      pScore=main.get(i,j);
      if (c1 != c2)       mutations.appendSubstitution(offset1 + length1 - 1 - i,c1,c2);
      --i;
      --j;
    }
 else     throw new RuntimeException();
  }
  return new BandedSemiLocalResult(offset1 + length1 - 1 - maxI,offset2 + length2 - 1 - maxJ,maxScore);
}

Fixed version (ground truth):
public static BandedSemiLocalResult semiLocalLeft0(final AffineGapAlignmentScoring<NucleotideSequence> scoring,final NucleotideSequence seq1,final NucleotideSequence seq2,int offset1,int length1,int offset2,int length2,final int width,final MutationsBuilder<NucleotideSequence> mutations,final MatrixCache cache){
  if (length1 == 0 || length2 == 0)   return new BandedSemiLocalResult(offset1 + length1,offset2 + length2,0);
  offset1+=length1;
  offset2+=length2;
  int minLength=Math.min(length1,length2) + width;
  length1=Math.min(length1,minLength);
  length2=Math.min(length2,minLength);
  offset1-=length1;
  offset2-=length2;
  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 + length1 - 1 - i),seq2.codeAt(offset2 + length2 - 1 - 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;
      }
    }
  }
  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 + length1 - 1 - i,seq1.codeAt(offset1 + length1 - 1 - 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 + length1 - 1 - i,seq2.codeAt(offset2 + length2 - 1 - j));
      --j;
    }
 else     if (i >= 0 && j >= 0 && pScore == main.get(i,j) + scoring.getScore(c1=seq1.codeAt(offset1 + length1 - 1 - i),c2=seq2.codeAt(offset2 + length2 - 1 - j))) {
      pScore=main.get(i,j);
      if (c1 != c2)       mutations.appendSubstitution(offset1 + length1 - 1 - i,c1,c2);
      --i;
      --j;
    }
 else     throw new RuntimeException();
  }
  return new BandedSemiLocalResult(offset1 + length1 - 1 - maxI,offset2 + length2 - 1 - maxJ,maxScore);
}