Program: 50323
Project: 50323
Buggy source:
private Alignments.AlignmentEntry andBack(final int index,int originalIndex,final Alignments.AlignmentEntry reduced){
  final Alignments.AlignmentEntry.Builder result=Alignments.AlignmentEntry.newBuilder(reduced);
  final int multiplicity=multiplicities.get(index);
  final int k=multiplicity - 1;
  multiplicities.set(index,k);
  if (!multiplicityFieldsAllMissing) {
    result.setMultiplicity(1);
  }
  final int queryIndex=queryIndices.getInt(originalIndex);
  result.setQueryIndex(queryIndex);
  if (originalIndex == 0 || reduced.hasPosition() || reduced.hasTargetIndex()) {
    previousPosition=reduced.getPosition();
    previousTargetIndex=reduced.getTargetIndex();
  }
 else {
    final int deltaPos=deltaPositions.getInt(deltaPosIndex);
    final int deltaTarget=deltaTargetIndices.getInt(deltaPosIndex);
    final int position=previousPosition + deltaPos;
    final int targetIndex=previousTargetIndex + deltaTarget;
    result.setPosition(position);
    result.setTargetIndex(targetIndex);
    previousPosition+=deltaPos;
    previousTargetIndex+=deltaTarget;
    deltaPosIndex++;
  }
  int anInt=mappingQualities.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setMappingQuality(anInt);
  }
  anInt=fragmentIndices.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setFragmentIndex(anInt);
  }
  anInt=matchingReverseStrand.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setMatchingReverseStrand(anInt == 1);
  }
  anInt=numberOfMismatches.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setNumberOfMismatches(anInt);
  }
  anInt=numberOfIndels.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setNumberOfIndels(anInt);
  }
  anInt=queryLengths.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setQueryLength(anInt);
  }
  anInt=queryAlignedLengths.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setQueryAlignedLength(anInt);
  }
  anInt=queryPositions.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setQueryPosition(anInt);
  }
  anInt=targetAlignedLengths.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setTargetAlignedLength(anInt);
  }
  final boolean entryMatchingReverseStrand=result.hasMatchingReverseStrand() ? result.getMatchingReverseStrand() : false;
  Alignments.RelatedAlignmentEntry link=pairLinks.decode(originalIndex,entryMatchingReverseStrand,reduced.getPairAlignmentLink());
  if (link != null) {
    result.setPairAlignmentLink(link);
  }
  link=forwardSpliceLinks.decode(originalIndex,entryMatchingReverseStrand,reduced.getSplicedForwardAlignmentLink());
  if (link != null) {
    result.setSplicedForwardAlignmentLink(link);
  }
  link=backwardSpliceLinks.decode(originalIndex,entryMatchingReverseStrand,reduced.getSplicedBackwardAlignmentLink());
  if (link != null) {
    result.setSplicedBackwardAlignmentLink(link);
  }
  final boolean templateHasSequenceVariations=reduced.getSequenceVariationsCount() > 0;
  final int numVariations=variationCount.getInt(index);
  for (int varIndex=0; varIndex < numVariations; varIndex++) {
    final Alignments.SequenceVariation template=templateHasSequenceVariations ? reduced.getSequenceVariations(varIndex) : null;
    final Alignments.SequenceVariation.Builder varBuilder=templateHasSequenceVariations ? Alignments.SequenceVariation.newBuilder(template) : Alignments.SequenceVariation.newBuilder();
    from.setLength(0);
    to.setLength(0);
    final int fromLength=fromLengths.getInt(varPositionIndex);
    final int toLength=toLengths.getInt(varPositionIndex);
    varBuilder.setPosition(varPositions.getInt(varPositionIndex));
    varBuilder.setReadIndex(varReadIndex.getInt(varPositionIndex));
    final int toQualLength=varToQualLength.getInt(varToQualsLength);
    varToQualsLength++;
    final byte[] quals=getQualArray(toQualLength);
    ++varPositionIndex;
    final int maxLength=Math.max(fromLength,toLength);
    for (int i=0; i < maxLength; i++) {
      final int fromTo=varFromTo.getInt(varFromToIndex++);
      if (i < fromLength) {
        from.append((char)(fromTo >> 8));
      }
      if (i < toLength) {
        to.append((char)(fromTo & 0xFF));
      }
      if (i < toQualLength) {
        if (varQualIndex < varQuals.size()) {
          quals[i]=(byte)varQuals.getInt(varQualIndex);
          ++varQualIndex;
        }
      }
    }
    varBuilder.setFrom(from.toString());
    varBuilder.setTo(to.toString());
    if (toQualLength > 0) {
      varBuilder.setToQuality(ByteString.copyFrom(quals));
    }
    if (templateHasSequenceVariations) {
      result.setSequenceVariations(varIndex,varBuilder);
    }
 else {
      result.addSequenceVariations(varBuilder);
    }
  }
  return result.build();
}

Fixed version (ground truth):
private Alignments.AlignmentEntry andBack(final int index,int originalIndex,final Alignments.AlignmentEntry reduced){
  final Alignments.AlignmentEntry.Builder result=Alignments.AlignmentEntry.newBuilder(reduced);
  final int multiplicity=multiplicities.get(index);
  final int k=multiplicity - 1;
  multiplicities.set(index,k);
  if (!multiplicityFieldsAllMissing) {
    result.setMultiplicity(1);
  }
  final int queryIndex=queryIndices.getInt(originalIndex);
  result.setQueryIndex(queryIndex);
  if (originalIndex == 0 || reduced.hasPosition() || reduced.hasTargetIndex()) {
    previousPosition=reduced.getPosition();
    previousTargetIndex=reduced.getTargetIndex();
  }
 else {
    final int deltaPos=deltaPositions.getInt(deltaPosIndex);
    final int deltaTarget=deltaTargetIndices.getInt(deltaPosIndex);
    final int position=previousPosition + deltaPos;
    final int targetIndex=previousTargetIndex + deltaTarget;
    result.setPosition(position);
    result.setTargetIndex(targetIndex);
    previousPosition+=deltaPos;
    previousTargetIndex+=deltaTarget;
    deltaPosIndex++;
  }
  int anInt=mappingQualities.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setMappingQuality(anInt);
  }
  anInt=fragmentIndices.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setFragmentIndex(anInt);
  }
  anInt=matchingReverseStrand.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setMatchingReverseStrand(anInt == 1);
  }
  anInt=numberOfMismatches.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setNumberOfMismatches(anInt);
  }
  anInt=numberOfIndels.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setNumberOfIndels(anInt);
  }
  final int queryLength=queryLengths.getInt(index);
  if (queryLength != MISSING_VALUE) {
    result.setQueryLength(queryLength);
  }
  anInt=queryAlignedLengths.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setQueryAlignedLength(anInt);
  }
  anInt=queryPositions.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setQueryPosition(anInt);
  }
  anInt=targetAlignedLengths.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setTargetAlignedLength(anInt);
  }
  final boolean entryMatchingReverseStrand=result.hasMatchingReverseStrand() ? result.getMatchingReverseStrand() : false;
  Alignments.RelatedAlignmentEntry link=pairLinks.decode(originalIndex,entryMatchingReverseStrand,reduced.getPairAlignmentLink());
  if (link != null) {
    result.setPairAlignmentLink(link);
  }
  link=forwardSpliceLinks.decode(originalIndex,entryMatchingReverseStrand,reduced.getSplicedForwardAlignmentLink());
  if (link != null) {
    result.setSplicedForwardAlignmentLink(link);
  }
  link=backwardSpliceLinks.decode(originalIndex,entryMatchingReverseStrand,reduced.getSplicedBackwardAlignmentLink());
  if (link != null) {
    result.setSplicedBackwardAlignmentLink(link);
  }
  final boolean templateHasSequenceVariations=reduced.getSequenceVariationsCount() > 0;
  final int numVariations=variationCount.getInt(index);
  for (int varIndex=0; varIndex < numVariations; varIndex++) {
    final Alignments.SequenceVariation template=templateHasSequenceVariations ? reduced.getSequenceVariations(varIndex) : null;
    final Alignments.SequenceVariation.Builder varBuilder=templateHasSequenceVariations ? Alignments.SequenceVariation.newBuilder(template) : Alignments.SequenceVariation.newBuilder();
    from.setLength(0);
    to.setLength(0);
    final int fromLength=fromLengths.getInt(varPositionIndex);
    final int toLength=toLengths.getInt(varPositionIndex);
    final int position=varPositions.getInt(varPositionIndex);
    varBuilder.setPosition(position);
    final int recodedReadIndex=varReadIndex.getInt(varPositionIndex);
    final int readIndex=entryMatchingReverseStrand ? recodedReadIndex + (queryLength - position) - 5 : -recodedReadIndex + position + 5;
    varBuilder.setReadIndex(readIndex);
    final int toQualLength=varToQualLength.getInt(varToQualsLength);
    varToQualsLength++;
    final byte[] quals=getQualArray(toQualLength);
    ++varPositionIndex;
    final int maxLength=Math.max(fromLength,toLength);
    for (int i=0; i < maxLength; i++) {
      final int fromTo=varFromTo.getInt(varFromToIndex++);
      if (i < fromLength) {
        from.append((char)(fromTo >> 8));
      }
      if (i < toLength) {
        to.append((char)(fromTo & 0xFF));
      }
      if (i < toQualLength) {
        if (varQualIndex < varQuals.size()) {
          quals[i]=(byte)varQuals.getInt(varQualIndex);
          ++varQualIndex;
        }
      }
    }
    varBuilder.setFrom(from.toString());
    varBuilder.setTo(to.toString());
    if (toQualLength > 0) {
      varBuilder.setToQuality(ByteString.copyFrom(quals));
    }
    if (templateHasSequenceVariations) {
      result.setSequenceVariations(varIndex,varBuilder);
    }
 else {
      result.addSequenceVariations(varBuilder);
    }
  }
  return result.build();
}