Program: 50388
Project: 50388
Buggy source:
public void writeGenotypes(VCFWriter statsWriter,SampleCountInfo[] sampleCounts,int position){
  boolean referenceAlleleSetForIndel=false;
  siteObserved=false;
  boolean siteHasIndel=false;
  referenceSet.clear();
  for (int sampleIndex=0; sampleIndex < numberOfSamples; sampleIndex++) {
    alleleSet.clear();
    SampleCountInfo sci=sampleCounts[sampleIndex];
    int totalCount=0;
    for (int genotypeIndex=0; genotypeIndex < sci.getGenotypeMaxIndex(); ++genotypeIndex) {
      final int sampleCount=sci.getGenotypeCount(genotypeIndex);
      totalCount+=sampleCount;
    }
    statsWriter.setSampleValue(goodBaseCountFieldIndex,sampleIndex,totalCount);
    statsWriter.setSampleValue(failBaseCountFieldIndex,sampleIndex,sci.failedCount);
    int baseIndex=0;
    int altGenotypeCount=0;
    genotypeBuffer.setLength(0);
    final MutableString baseCountString=new MutableString();
    statsWriter.clearAlternateAlleles();
    for (int genotypeIndex=0; genotypeIndex < sci.getGenotypeMaxIndex(); ++genotypeIndex) {
      final int sampleCount=sci.getGenotypeCount(genotypeIndex);
      String genotype=sci.getGenotypeString(genotypeIndex);
      if (sampleCount > 0 && genotypeIndex != SampleCountInfo.BASE_OTHER_INDEX) {
        siteObserved=true;
        if (sci.isIndel(genotypeIndex)) {
          siteHasIndel=true;
        }
        if (!sci.isReferenceGenotype(genotypeIndex)) {
          statsWriter.addAlternateAllele(genotype);
          altGenotypeCount++;
          updateReferenceSet(sci.getReferenceGenotype());
        }
 else {
          if (sci.isIndel(genotypeIndex)) {
            siteHasIndel=true;
            genotype=sci.getReferenceGenotype();
          }
          updateReferenceSet(genotype);
        }
        alleleSet.add(genotype);
        genotypeBuffer.append(genotype);
        genotypeBuffer.append('/');
      }
      baseCountString.append(genotype);
      baseCountString.append('=');
      baseCountString.append(Integer.toString(sampleCount));
      baseCountString.append(',');
    }
    if (alleleSet.size() == 1) {
      genotypeBuffer.append(genotypeBuffer.copy());
    }
    baseCountString.setLength(baseCountString.length() - 1);
    statsWriter.setSampleValue(baseCountFieldIndex,sampleIndex,baseCountString);
    if (siteObserved) {
      if (genotypeBuffer.length() > 1) {
        genotypeBuffer.setLength(genotypeBuffer.length() - 1);
      }
      if (referenceSet.size() <= 1) {
        if (referenceSet.isEmpty()) {
          statsWriter.setReferenceAllele(sci.getReferenceGenotype());
        }
 else {
          statsWriter.setReferenceAllele(referenceSet.toArray(singleton)[0]);
        }
      }
 else {
        LOG.error(String.format("String_Node_Str",position,referenceSet));
        int maxLength=0;
        for (        final String ref : referenceSet) {
          if (ref.length() > maxLength) {
            statsWriter.setReferenceAllele(ref);
            maxLength=ref.length();
          }
        }
      }
      statsWriter.setSampleValue(genotypeFieldIndex,sampleIndex,statsWriter.codeGenotype(genotypeBuffer.toString()));
    }
 else {
      statsWriter.setSampleValue(genotypeFieldIndex,sampleIndex,"String_Node_Str");
    }
  }
  if (indelFlagFieldIndex != -1) {
    statsWriter.setFlag(indelFlagFieldIndex,siteHasIndel);
  }
}

Fixed version (ground truth):
public void writeGenotypes(VCFWriter statsWriter,SampleCountInfo[] sampleCounts,int position){
  boolean referenceAlleleSetForIndel=false;
  siteObserved=false;
  boolean siteHasIndel=false;
  referenceSet.clear();
  statsWriter.clearAlternateAlleles();
  for (int sampleIndex=0; sampleIndex < numberOfSamples; sampleIndex++) {
    alleleSet.clear();
    SampleCountInfo sci=sampleCounts[sampleIndex];
    int totalCount=0;
    for (int genotypeIndex=0; genotypeIndex < sci.getGenotypeMaxIndex(); ++genotypeIndex) {
      final int sampleCount=sci.getGenotypeCount(genotypeIndex);
      totalCount+=sampleCount;
    }
    statsWriter.setSampleValue(goodBaseCountFieldIndex,sampleIndex,totalCount);
    statsWriter.setSampleValue(failBaseCountFieldIndex,sampleIndex,sci.failedCount);
    int baseIndex=0;
    int altGenotypeCount=0;
    genotypeBuffer.setLength(0);
    final MutableString baseCountString=new MutableString();
    for (int genotypeIndex=0; genotypeIndex < sci.getGenotypeMaxIndex(); ++genotypeIndex) {
      final int sampleCount=sci.getGenotypeCount(genotypeIndex);
      String genotype=sci.getGenotypeString(genotypeIndex);
      if (sampleCount > 0 && genotypeIndex != SampleCountInfo.BASE_OTHER_INDEX) {
        siteObserved=true;
        if (sci.isIndel(genotypeIndex)) {
          siteHasIndel=true;
        }
        if (!sci.isReferenceGenotype(genotypeIndex)) {
          statsWriter.addAlternateAllele(genotype);
          altGenotypeCount++;
          updateReferenceSet(sci.getReferenceGenotype());
        }
 else {
          if (sci.isIndel(genotypeIndex)) {
            siteHasIndel=true;
            genotype=sci.getReferenceGenotype();
          }
          updateReferenceSet(genotype);
        }
        alleleSet.add(genotype);
        genotypeBuffer.append(genotype);
        genotypeBuffer.append('/');
      }
      baseCountString.append(genotype);
      baseCountString.append('=');
      baseCountString.append(Integer.toString(sampleCount));
      baseCountString.append(',');
    }
    if (alleleSet.size() == 1) {
      genotypeBuffer.append(genotypeBuffer.copy());
    }
    baseCountString.setLength(baseCountString.length() - 1);
    statsWriter.setSampleValue(baseCountFieldIndex,sampleIndex,baseCountString);
    if (siteObserved) {
      if (genotypeBuffer.length() > 1) {
        genotypeBuffer.setLength(genotypeBuffer.length() - 1);
      }
      if (referenceSet.size() <= 1) {
        if (referenceSet.isEmpty()) {
          statsWriter.setReferenceAllele(sci.getReferenceGenotype());
        }
 else {
          statsWriter.setReferenceAllele(referenceSet.toArray(singleton)[0]);
        }
      }
 else {
        LOG.error(String.format("String_Node_Str",position,referenceSet));
        int maxLength=0;
        for (        final String ref : referenceSet) {
          if (ref.length() > maxLength) {
            statsWriter.setReferenceAllele(ref);
            maxLength=ref.length();
          }
        }
      }
      statsWriter.setSampleValue(genotypeFieldIndex,sampleIndex,statsWriter.codeGenotype(genotypeBuffer.toString()));
    }
 else {
      statsWriter.setSampleValue(genotypeFieldIndex,sampleIndex,"String_Node_Str");
    }
  }
  if (indelFlagFieldIndex != -1) {
    statsWriter.setFlag(indelFlagFieldIndex,siteHasIndel);
  }
}