Program: 30498
Project: 30498
Buggy source:
private void nextContainer() throws IOException, IllegalArgumentException, IllegalAccessException, CRAMException {
  if (containerIterator != null) {
    if (!containerIterator.hasNext()) {
      records.clear();
      nextRecord=null;
      return;
    }
    container=containerIterator.next();
    if (container.isEOF()) {
      records.clear();
      nextRecord=null;
      return;
    }
  }
 else {
    container=ContainerIO.readContainer(cramHeader.getVersion(),countingInputStream);
    if (container.isEOF()) {
      records.clear();
      nextRecord=null;
      return;
    }
  }
  if (records == null)   records=new ArrayList<SAMRecord>(container.nofRecords);
 else   records.clear();
  if (cramRecords == null)   cramRecords=new ArrayList<CramCompressionRecord>(container.nofRecords);
 else   cramRecords.clear();
  parser.getRecords(container,cramRecords);
  if (container.sequenceId == SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX) {
    refs=new byte[]{};
  }
 else   if (container.sequenceId == -2) {
    refs=null;
    prevSeqId=-2;
  }
 else   if (prevSeqId < 0 || prevSeqId != container.sequenceId) {
    final SAMSequenceRecord sequence=cramHeader.getSamFileHeader().getSequence(container.sequenceId);
    refs=referenceSource.getReferenceBases(sequence,true);
    if (refs == null) {
      throw new CRAMException(String.format("String_Node_Str",sequence.getSequenceName()));
    }
    prevSeqId=container.sequenceId;
  }
  for (int i=0; i < container.slices.length; i++) {
    final Slice slice=container.slices[i];
    if (slice.sequenceId < 0)     continue;
    if (validationStringency != ValidationStringency.SILENT && !slice.validateRefMD5(refs)) {
      log.error(String.format("String_Node_Str",slice.sequenceId,slice.alignmentStart,slice.alignmentSpan,String.format("String_Node_Str",new BigInteger(1,slice.refMD5))));
    }
  }
  normalizer.normalize(cramRecords,refs,0,container.header.substitutionMatrix);
  final Cram2SamRecordFactory cramToSamRecordFactory=new Cram2SamRecordFactory(cramHeader.getSamFileHeader());
  for (  final CramCompressionRecord cramRecord : cramRecords) {
    final SAMRecord samRecord=cramToSamRecordFactory.create(cramRecord);
    if (!cramRecord.isSegmentUnmapped()) {
      final SAMSequenceRecord sequence=cramHeader.getSamFileHeader().getSequence(cramRecord.sequenceId);
      refs=referenceSource.getReferenceBases(sequence,true);
      if (samRecord.getReadBases() != SAMRecord.NULL_SEQUENCE)       SequenceUtil.calculateMdAndNmTags(samRecord,refs,restoreMDTag,restoreNMTag);
    }
    samRecord.setValidationStringency(validationStringency);
    if (validationStringency != ValidationStringency.SILENT) {
      final List<SAMValidationError> validationErrors=samRecord.isValid();
      SAMUtils.processValidationErrors(validationErrors,samRecordIndex,validationStringency);
    }
    if (mReader != null) {
      final long chunkStart=(container.offset << 16) | cramRecord.sliceIndex;
      final long chunkEnd=((container.offset << 16) | cramRecord.sliceIndex) + 1;
      nextRecord.setFileSource(new SAMFileSource(mReader,new BAMFileSpan(new Chunk(chunkStart,chunkEnd))));
    }
    records.add(samRecord);
    samRecordIndex++;
  }
  cramRecords.clear();
  iterator=records.iterator();
}

Fixed version (ground truth):
private void nextContainer() throws IOException, IllegalArgumentException, IllegalAccessException, CRAMException {
  if (containerIterator != null) {
    if (!containerIterator.hasNext()) {
      records.clear();
      nextRecord=null;
      return;
    }
    container=containerIterator.next();
    if (container.isEOF()) {
      records.clear();
      nextRecord=null;
      return;
    }
  }
 else {
    container=ContainerIO.readContainer(cramHeader.getVersion(),countingInputStream);
    if (container.isEOF()) {
      records.clear();
      nextRecord=null;
      return;
    }
  }
  if (records == null)   records=new ArrayList<SAMRecord>(container.nofRecords);
 else   records.clear();
  if (cramRecords == null)   cramRecords=new ArrayList<CramCompressionRecord>(container.nofRecords);
 else   cramRecords.clear();
  parser.getRecords(container,cramRecords,validationStringency);
  if (container.sequenceId == SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX) {
    refs=new byte[]{};
  }
 else   if (container.sequenceId == -2) {
    refs=null;
    prevSeqId=-2;
  }
 else   if (prevSeqId < 0 || prevSeqId != container.sequenceId) {
    final SAMSequenceRecord sequence=cramHeader.getSamFileHeader().getSequence(container.sequenceId);
    refs=referenceSource.getReferenceBases(sequence,true);
    if (refs == null) {
      throw new CRAMException(String.format("String_Node_Str",sequence.getSequenceName()));
    }
    prevSeqId=container.sequenceId;
  }
  for (int i=0; i < container.slices.length; i++) {
    final Slice slice=container.slices[i];
    if (slice.sequenceId < 0)     continue;
    if (validationStringency != ValidationStringency.SILENT && !slice.validateRefMD5(refs)) {
      log.error(String.format("String_Node_Str",slice.sequenceId,slice.alignmentStart,slice.alignmentSpan,String.format("String_Node_Str",new BigInteger(1,slice.refMD5))));
    }
  }
  normalizer.normalize(cramRecords,refs,0,container.header.substitutionMatrix);
  final Cram2SamRecordFactory cramToSamRecordFactory=new Cram2SamRecordFactory(cramHeader.getSamFileHeader());
  for (  final CramCompressionRecord cramRecord : cramRecords) {
    final SAMRecord samRecord=cramToSamRecordFactory.create(cramRecord);
    if (!cramRecord.isSegmentUnmapped()) {
      final SAMSequenceRecord sequence=cramHeader.getSamFileHeader().getSequence(cramRecord.sequenceId);
      refs=referenceSource.getReferenceBases(sequence,true);
      if (samRecord.getReadBases() != SAMRecord.NULL_SEQUENCE)       SequenceUtil.calculateMdAndNmTags(samRecord,refs,restoreMDTag,restoreNMTag);
    }
    samRecord.setValidationStringency(validationStringency);
    if (validationStringency != ValidationStringency.SILENT) {
      final List<SAMValidationError> validationErrors=samRecord.isValid();
      SAMUtils.processValidationErrors(validationErrors,samRecordIndex,validationStringency);
    }
    if (mReader != null) {
      final long chunkStart=(container.offset << 16) | cramRecord.sliceIndex;
      final long chunkEnd=((container.offset << 16) | cramRecord.sliceIndex) + 1;
      nextRecord.setFileSource(new SAMFileSource(mReader,new BAMFileSpan(new Chunk(chunkStart,chunkEnd))));
    }
    records.add(samRecord);
    samRecordIndex++;
  }
  cramRecords.clear();
  iterator=records.iterator();
}