Program: 17101
Project: 17101
Buggy source:
/** 
 * Creates an   {@link AlignedSequence} for the given {@link Sequence} in a local alignment.
 * @param original the original {@link Sequence} before alignment
 * @param steps lists whether the sequence aligns a {@link Compound} or gap at each index of the alignment
 * @param numBefore number of {@link Compound}s before a local alignment
 * @param numAfter number of {@link Compound}s after a local alignment
 * @throws IllegalArgumentException if given sequence does not fit in alignment
 */
public SimpleAlignedSequence(Sequence<C> original,List<Step> steps,int numBefore,int numAfter){
  this.original=original;
  this.numBefore=numBefore;
  this.numAfter=numAfter;
  length=steps.size();
  SimpleAlignedSequence<C> prev=null;
  if (original instanceof SimpleAlignedSequence<?>) {
    prev=(SimpleAlignedSequence<C>)original;
    this.original=prev.getOriginalSequence();
    this.numBefore+=prev.numBefore;
    this.numAfter+=prev.numAfter;
  }
  List<Location> sublocations=new ArrayList<Location>();
  int start=0, step=0, oStep=numBefore + numAfter, oMax=this.original.getLength(), pStep=0, pMax=(prev == null) ? 0 : prev.getLength();
  boolean inGap=true;
  for (; step < length; step++) {
    boolean isGapStep=(steps.get(step) == Step.GAP), isGapPrev=(prev != null && pStep < pMax && prev.isGap(pStep + 1));
    if (!inGap && (isGapStep || isGapPrev)) {
      inGap=true;
      sublocations.add(new SimpleLocation(start,step,Strand.UNDEFINED));
    }
 else     if (!isGapStep && !isGapPrev) {
      oStep++;
      if (inGap) {
        inGap=false;
        start=step + 1;
      }
    }
    if (!isGapStep) {
      pStep+=(prev == null) ? 0 : 1;
    }
  }
  if (!inGap) {
    sublocations.add(new SimpleLocation(start,step,Strand.UNDEFINED));
  }
  location=(sublocations.size() == 1) ? sublocations.get(0) : new SimpleLocation(sublocations.get(0).getStart(),sublocations.get(sublocations.size() - 1).getEnd(),Strand.UNDEFINED,false,sublocations);
  if (step != length || oStep != oMax || pStep != pMax) {
    throw new IllegalArgumentException("String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * Creates an   {@link AlignedSequence} for the given {@link Sequence} in a local alignment.
 * @param original the original {@link Sequence} before alignment
 * @param steps lists whether the sequence aligns a {@link Compound} or gap at each index of the alignment
 * @param numBefore number of {@link Compound}s before a local alignment
 * @param numAfter number of {@link Compound}s after a local alignment
 * @throws IllegalArgumentException if given sequence does not fit in alignment
 */
public SimpleAlignedSequence(Sequence<C> original,List<Step> steps,int numBefore,int numAfter){
  this.original=original;
  this.numBefore=numBefore;
  this.numAfter=numAfter;
  length=steps.size();
  SimpleAlignedSequence<C> prev=null;
  if (original instanceof SimpleAlignedSequence<?>) {
    prev=(SimpleAlignedSequence<C>)original;
    this.original=prev.getOriginalSequence();
    this.numBefore+=prev.numBefore;
    this.numAfter+=prev.numAfter;
  }
  List<Location> sublocations=new ArrayList<Location>();
  int start=0, step=0, oStep=numBefore + numAfter, oMax=this.original.getLength(), pStep=0, pMax=(prev == null) ? 0 : prev.getLength();
  boolean inGap=true;
  for (; step < length; step++) {
    boolean isGapStep=(steps.get(step) == Step.GAP), isGapPrev=(pStep < pMax && prev.isGap(pStep + 1));
    if (!isGapStep && !isGapPrev) {
      oStep++;
      if (inGap) {
        inGap=false;
        start=step + 1;
      }
    }
 else     if (!inGap) {
      inGap=true;
      sublocations.add(new SimpleLocation(start,step,Strand.UNDEFINED));
    }
    if (prev != null && !isGapStep) {
      pStep++;
    }
  }
  if (!inGap) {
    sublocations.add(new SimpleLocation(start,step,Strand.UNDEFINED));
  }
  location=(sublocations.size() == 1) ? sublocations.get(0) : new SimpleLocation(sublocations.get(0).getStart(),sublocations.get(sublocations.size() - 1).getEnd(),Strand.UNDEFINED,false,sublocations);
  if (step != length || oStep != oMax || pStep != pMax) {
    throw new IllegalArgumentException("String_Node_Str");
  }
}