Program: 30493
Project: 30493
Buggy source:
/** 
 * SAM record and quality format validations are combined into a single method because validation must be completed in only a single pass of the SamRecords (because a SamReader's iterator() method may not return the same records on a subsequent call).
 */
private void validateSamRecordsAndQualityFormat(final Iterable<SAMRecord> samRecords,final SAMFileHeader header){
  final SAMRecordIterator iter=(SAMRecordIterator)samRecords.iterator();
  final ProgressLogger progress=new ProgressLogger(log,10000000,"String_Node_Str");
  final QualityEncodingDetector qualityDetector=new QualityEncodingDetector();
  try {
    while (iter.hasNext()) {
      final SAMRecord record=iter.next();
      qualityDetector.add(record);
      final long recordNumber=progress.getCount() + 1;
      final Collection<SAMValidationError> errors=record.isValid();
      if (errors != null) {
        for (        final SAMValidationError error : errors) {
          error.setRecordNumber(recordNumber);
          addError(error);
        }
      }
      validateMateFields(record,recordNumber);
      validateSortOrder(record,recordNumber);
      validateReadGroup(record,header);
      final boolean cigarIsValid=validateCigar(record,recordNumber);
      if (cigarIsValid) {
        validateNmTag(record,recordNumber);
      }
      validateSecondaryBaseCalls(record,recordNumber);
      validateTags(record,recordNumber);
      if (sequenceDictionaryEmptyAndNoWarningEmitted && !record.getReadUnmappedFlag()) {
        addError(new SAMValidationError(Type.MISSING_SEQUENCE_DICTIONARY,"String_Node_Str",null));
        sequenceDictionaryEmptyAndNoWarningEmitted=false;
      }
      progress.record(record);
    }
    try {
      if (progress.getCount() > 0) {
        final FastqQualityFormat format=qualityDetector.generateBestGuess(QualityEncodingDetector.FileContext.SAM,FastqQualityFormat.Standard);
        if (format != FastqQualityFormat.Standard) {
          addError(new SAMValidationError(Type.INVALID_QUALITY_FORMAT,String.format("String_Node_Str",format,FastqQualityFormat.Standard),null));
        }
      }
    }
 catch (    SAMException e) {
      addError(new SAMValidationError(Type.INVALID_QUALITY_FORMAT,e.getMessage(),null));
    }
  }
 catch (  SAMFormatException e) {
    final String msg="String_Node_Str" + progress.getCount() + 1;
    out.println(msg);
    throw new SAMException(msg,e);
  }
catch (  FileTruncatedException e) {
    addError(new SAMValidationError(Type.TRUNCATED_FILE,"String_Node_Str",null));
  }
 finally {
    iter.close();
  }
}

Fixed version (ground truth):
/** 
 * SAM record and quality format validations are combined into a single method because validation must be completed in only a single pass of the SamRecords (because a SamReader's iterator() method may not return the same records on a subsequent call).
 */
private void validateSamRecordsAndQualityFormat(final Iterable<SAMRecord> samRecords,final SAMFileHeader header){
  final SAMRecordIterator iter=(SAMRecordIterator)samRecords.iterator();
  final ProgressLogger progress=new ProgressLogger(log,10000000,"String_Node_Str");
  final QualityEncodingDetector qualityDetector=new QualityEncodingDetector();
  try {
    while (iter.hasNext()) {
      final SAMRecord record=iter.next();
      qualityDetector.add(record);
      final long recordNumber=progress.getCount() + 1;
      final Collection<SAMValidationError> errors=record.isValid();
      if (errors != null) {
        for (        final SAMValidationError error : errors) {
          error.setRecordNumber(recordNumber);
          addError(error);
        }
      }
      validateMateFields(record,recordNumber);
      final boolean hasValidSortOrder=validateSortOrder(record,recordNumber);
      validateReadGroup(record,header);
      final boolean cigarIsValid=validateCigar(record,recordNumber);
      if (cigarIsValid) {
        try {
          validateNmTag(record,recordNumber);
        }
 catch (        SAMException e) {
          if (hasValidSortOrder) {
            throw e;
          }
        }
      }
      validateSecondaryBaseCalls(record,recordNumber);
      validateTags(record,recordNumber);
      if (sequenceDictionaryEmptyAndNoWarningEmitted && !record.getReadUnmappedFlag()) {
        addError(new SAMValidationError(Type.MISSING_SEQUENCE_DICTIONARY,"String_Node_Str",null));
        sequenceDictionaryEmptyAndNoWarningEmitted=false;
      }
      progress.record(record);
    }
    try {
      if (progress.getCount() > 0) {
        final FastqQualityFormat format=qualityDetector.generateBestGuess(QualityEncodingDetector.FileContext.SAM,FastqQualityFormat.Standard);
        if (format != FastqQualityFormat.Standard) {
          addError(new SAMValidationError(Type.INVALID_QUALITY_FORMAT,String.format("String_Node_Str",format,FastqQualityFormat.Standard),null));
        }
      }
    }
 catch (    SAMException e) {
      addError(new SAMValidationError(Type.INVALID_QUALITY_FORMAT,e.getMessage(),null));
    }
  }
 catch (  SAMFormatException e) {
    final String msg="String_Node_Str" + progress.getCount() + 1;
    out.println(msg);
    throw new SAMException(msg,e);
  }
catch (  FileTruncatedException e) {
    addError(new SAMValidationError(Type.TRUNCATED_FILE,"String_Node_Str",null));
  }
 finally {
    iter.close();
  }
}