Program: 50317
Project: 50317
Buggy source:
private Alignments.AlignmentEntry andBack(final int index,int originalIndex,final Alignments.AlignmentEntry reduced,int streamVersion){
  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++;
  }
  if (streamVersion >= 2) {
    final int numReadQualScores=numReadQualityScores.get(index);
    if (numReadQualScores > 0) {
      final byte[] scores=new byte[numReadQualScores];
      for (int i=0; i < numReadQualScores; i++) {
        scores[i]=(byte)allReadQualityScores.getInt(qualScoreIndex++);
      }
      result.setReadQualityScores(ByteString.copyFrom(scores));
    }
  }
  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);
  }
  anInt=sampleIndices.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setSampleIndex(anInt);
  }
  anInt=readOriginIndices.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setReadOriginIndex(anInt);
  }
  anInt=pairFlags.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setPairFlags(anInt);
  }
  anInt=scores.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setScore(Float.intBitsToFloat(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);
  }
  decodeInsertSize(result,index);
  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();
}

Fixed version (ground truth):
private Alignments.AlignmentEntry andBack(final int index,int originalIndex,final Alignments.AlignmentEntry reduced,int streamVersion){
  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++;
  }
  if (streamVersion >= 2) {
    final int numReadQualScores=numReadQualityScores.get(index);
    if (numReadQualScores > 0) {
      final byte[] scores=new byte[numReadQualScores];
      for (int i=0; i < numReadQualScores; i++) {
        scores[i]=(byte)allReadQualityScores.getInt(qualScoreIndex++);
      }
      result.setReadQualityScores(ByteString.copyFrom(scores));
    }
  }
  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);
  }
  anInt=sampleIndices.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setSampleIndex(anInt);
  }
  anInt=readOriginIndices.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setReadOriginIndex(anInt);
  }
  anInt=pairFlags.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setPairFlags(anInt);
  }
  anInt=scores.getInt(index);
  if (anInt != MISSING_VALUE) {
    result.setScore(Float.intBitsToFloat(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);
  }
  decodeInsertSize(result,index);
  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(varToQualLengthIndex);
    varToQualLengthIndex++;
    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();
}