Program: 141267
Project: 141267
Buggy source:
public static void countReadsInFeatures(final InputStream samFile,final File gffFile,final File output,final String stranded,final String overlapMode,final String featureType,final String attributeId,final boolean quiet,final int minAverageQual,final File samOutFile) throws EoulsanException, IOException, BadBioEntryException {
  final GenomicArray<String> features=new GenomicArray<String>();
  final Map<String,Integer> counts=Utils.newHashMap();
  Writer writer=new FileWriter(output);
  boolean pairedEnd=false;
  final GFFReader gffReader=new GFFReader(gffFile);
  for (  final GFFEntry gff : gffReader) {
    if (featureType.equals(gff.getType())) {
      final String featureId=gff.getAttributeValue(attributeId);
      if (featureId == null) {
        writer.close();
        gffReader.close();
        throw new EoulsanException("String_Node_Str" + featureType + "String_Node_Str"+ attributeId+ "String_Node_Str");
      }
      if (stranded.equals("String_Node_Str") && '.' == gff.getStrand()) {
        writer.close();
        gffReader.close();
        throw new EoulsanException("String_Node_Str" + featureType + "String_Node_Str"+ "String_Node_Str");
      }
      boolean saveStrandInfo="String_Node_Str".equals(stranded) || "String_Node_Str".equals(stranded);
      features.addEntry(new GenomicInterval(gff,saveStrandInfo),featureId);
      counts.put(featureId,0);
    }
  }
  gffReader.throwException();
  gffReader.close();
  if (counts.size() == 0) {
    writer.close();
    throw new EoulsanException("String_Node_Str" + featureType + "String_Node_Str");
  }
  List<GenomicInterval> ivSeq=new ArrayList<GenomicInterval>();
  final SAMFileReader inputSam=new SAMFileReader(samFile);
  final SAMFileReader input=new SAMFileReader(samFile);
  SAMRecordIterator samIterator=input.iterator();
  SAMRecord firstRecord;
  if (samIterator.hasNext())   firstRecord=samIterator.next();
 else {
    writer.close();
    input.close();
    inputSam.close();
    throw new EoulsanException("String_Node_Str");
  }
  if (firstRecord.getReadPairedFlag())   pairedEnd=true;
  input.close();
  int empty=0;
  int ambiguous=0;
  int notaligned=0;
  int lowqual=0;
  int nonunique=0;
  int i=0;
  SAMRecord sam1=null, sam2=null;
  for (  final SAMRecord samRecord : inputSam) {
    i++;
    if (i % 1000000 == 0)     System.out.println(i + "String_Node_Str");
    if (!pairedEnd) {
      ivSeq.clear();
      if (samRecord.getReadUnmappedFlag()) {
        notaligned++;
        continue;
      }
      if (samRecord.getAttribute("String_Node_Str") != null && samRecord.getIntegerAttribute("String_Node_Str") > 1) {
        nonunique++;
        continue;
      }
      if (samRecord.getMappingQuality() < minAverageQual) {
        lowqual++;
        continue;
      }
      ivSeq.addAll(addIntervals(samRecord,stranded));
    }
 else {
      if (sam1 != null && sam2 != null) {
        sam1=null;
        sam2=null;
        ivSeq.clear();
      }
      if (samRecord.getFirstOfPairFlag())       sam1=samRecord;
 else       sam2=samRecord;
      if (sam1 == null || sam2 == null)       continue;
      if (!sam1.getReadName().equals(sam2.getReadName())) {
        sam1=sam2;
        sam2=null;
        continue;
      }
      if (sam1 != null && !sam1.getReadUnmappedFlag()) {
        ivSeq.addAll(addIntervals(sam1,stranded));
      }
      if (sam2 != null && !sam2.getReadUnmappedFlag()) {
        ivSeq.addAll(addIntervals(sam2,stranded));
      }
      if (sam1.getReadUnmappedFlag() && sam2.getReadUnmappedFlag()) {
        notaligned++;
        continue;
      }
      if ((sam1.getAttribute("String_Node_Str") != null && sam1.getIntegerAttribute("String_Node_Str") > 1) || (sam2.getAttribute("String_Node_Str") != null && sam2.getIntegerAttribute("String_Node_Str") > 1)) {
        nonunique++;
        continue;
      }
      if (sam1.getMappingQuality() < minAverageQual || sam2.getMappingQuality() < minAverageQual) {
        lowqual++;
        continue;
      }
    }
    Set<String> fs=null;
    fs=featuresOverlapped(ivSeq,features,overlapMode,stranded);
    if (fs == null)     fs=new HashSet<String>();
switch (fs.size()) {
case 0:
      empty++;
    break;
case 1:
  final String id=fs.iterator().next();
counts.put(id,counts.get(id) + 1);
break;
default :
ambiguous++;
break;
}
}
inputSam.close();
final List<String> keysSorted=new ArrayList<String>(counts.keySet());
Collections.sort(keysSorted);
for (String key : keysSorted) {
writer.write(key + "String_Node_Str" + counts.get(key)+ "String_Node_Str");
}
writer.write("String_Node_Str" + empty + '\n');
writer.write("String_Node_Str" + ambiguous + '\n');
writer.write("String_Node_Str" + lowqual + '\n');
writer.write("String_Node_Str" + notaligned + '\n');
writer.write("String_Node_Str" + nonunique + '\n');
writer.close();
}

Fixed version (ground truth):
public static void countReadsInFeatures(final InputStream samFile,final File gffFile,final File output,final String stranded,final String overlapMode,final String featureType,final String attributeId,final boolean quiet,final int minAverageQual,final File samOutFile) throws EoulsanException, IOException, BadBioEntryException {
  final GenomicArray<String> features=new GenomicArray<String>();
  final Map<String,Integer> counts=Utils.newHashMap();
  Writer writer=FileUtils.createBufferedWriter(output);
  boolean pairedEnd=false;
  final GFFReader gffReader=new GFFReader(gffFile);
  for (  final GFFEntry gff : gffReader) {
    if (featureType.equals(gff.getType())) {
      final String featureId=gff.getAttributeValue(attributeId);
      if (featureId == null) {
        writer.close();
        gffReader.close();
        throw new EoulsanException("String_Node_Str" + featureType + "String_Node_Str"+ attributeId+ "String_Node_Str");
      }
      if (stranded.equals("String_Node_Str") && '.' == gff.getStrand()) {
        writer.close();
        gffReader.close();
        throw new EoulsanException("String_Node_Str" + featureType + "String_Node_Str"+ "String_Node_Str");
      }
      boolean saveStrandInfo="String_Node_Str".equals(stranded) || "String_Node_Str".equals(stranded);
      features.addEntry(new GenomicInterval(gff,saveStrandInfo),featureId);
      counts.put(featureId,0);
    }
  }
  gffReader.throwException();
  gffReader.close();
  if (counts.size() == 0) {
    writer.close();
    throw new EoulsanException("String_Node_Str" + featureType + "String_Node_Str");
  }
  List<GenomicInterval> ivSeq=new ArrayList<GenomicInterval>();
  final SAMFileReader inputSam=new SAMFileReader(samFile);
  final SAMFileReader input=new SAMFileReader(samFile);
  SAMRecordIterator samIterator=input.iterator();
  SAMRecord firstRecord;
  if (samIterator.hasNext())   firstRecord=samIterator.next();
 else {
    writer.close();
    input.close();
    inputSam.close();
    throw new EoulsanException("String_Node_Str");
  }
  if (firstRecord.getReadPairedFlag())   pairedEnd=true;
  input.close();
  int empty=0;
  int ambiguous=0;
  int notaligned=0;
  int lowqual=0;
  int nonunique=0;
  int i=0;
  SAMRecord sam1=null, sam2=null;
  for (  final SAMRecord samRecord : inputSam) {
    i++;
    if (i % 1000000 == 0)     System.out.println(i + "String_Node_Str");
    if (!pairedEnd) {
      ivSeq.clear();
      if (samRecord.getReadUnmappedFlag()) {
        notaligned++;
        continue;
      }
      if (samRecord.getAttribute("String_Node_Str") != null && samRecord.getIntegerAttribute("String_Node_Str") > 1) {
        nonunique++;
        continue;
      }
      if (samRecord.getMappingQuality() < minAverageQual) {
        lowqual++;
        continue;
      }
      ivSeq.addAll(addIntervals(samRecord,stranded));
    }
 else {
      if (sam1 != null && sam2 != null) {
        sam1=null;
        sam2=null;
        ivSeq.clear();
      }
      if (samRecord.getFirstOfPairFlag())       sam1=samRecord;
 else       sam2=samRecord;
      if (sam1 == null || sam2 == null)       continue;
      if (!sam1.getReadName().equals(sam2.getReadName())) {
        sam1=sam2;
        sam2=null;
        continue;
      }
      if (sam1 != null && !sam1.getReadUnmappedFlag()) {
        ivSeq.addAll(addIntervals(sam1,stranded));
      }
      if (sam2 != null && !sam2.getReadUnmappedFlag()) {
        ivSeq.addAll(addIntervals(sam2,stranded));
      }
      if (sam1.getReadUnmappedFlag() && sam2.getReadUnmappedFlag()) {
        notaligned++;
        continue;
      }
      if ((sam1.getAttribute("String_Node_Str") != null && sam1.getIntegerAttribute("String_Node_Str") > 1) || (sam2.getAttribute("String_Node_Str") != null && sam2.getIntegerAttribute("String_Node_Str") > 1)) {
        nonunique++;
        continue;
      }
      if (sam1.getMappingQuality() < minAverageQual || sam2.getMappingQuality() < minAverageQual) {
        lowqual++;
        continue;
      }
    }
    Set<String> fs=null;
    fs=featuresOverlapped(ivSeq,features,overlapMode,stranded);
    if (fs == null)     fs=new HashSet<String>();
switch (fs.size()) {
case 0:
      empty++;
    break;
case 1:
  final String id=fs.iterator().next();
counts.put(id,counts.get(id) + 1);
break;
default :
ambiguous++;
break;
}
}
inputSam.close();
final List<String> keysSorted=new ArrayList<String>(counts.keySet());
Collections.sort(keysSorted);
for (String key : keysSorted) {
writer.write(key + "String_Node_Str" + counts.get(key)+ "String_Node_Str");
}
writer.write("String_Node_Str" + empty + '\n');
writer.write("String_Node_Str" + ambiguous + '\n');
writer.write("String_Node_Str" + lowqual + '\n');
writer.write("String_Node_Str" + notaligned + '\n');
writer.write("String_Node_Str" + nonunique + '\n');
writer.close();
}