Program: 132270
Project: 132270
Buggy source:
void createShardsForReference(SAMSequenceRecord reference,Contig contig){
  final BitSet overlappingBins=GenomicIndexUtil.regionToBins((int)contig.start,(int)contig.end);
  if (overlappingBins == null) {
    LOG.warning("String_Node_Str" + contig.start + "String_Node_Str"+ contig.end);
    return;
  }
  BAMShard currentShard=null;
  for (int binIndex=overlappingBins.nextSetBit(0); binIndex >= 0; binIndex=overlappingBins.nextSetBit(binIndex + 1)) {
    final Bin bin=index.getBinData(reference.getSequenceIndex(),binIndex);
    if (bin == null) {
      continue;
    }
    if (LOG.isLoggable(Level.FINE)) {
      LOG.fine("String_Node_Str" + index.getFirstLocusInBin(bin) + "String_Node_Str"+ index.getLastLocusInBin(bin));
    }
    if (index.getLevelForBin(bin) != (GenomicIndexUtil.LEVEL_STARTS.length - 1)) {
      if (LOG.isLoggable(Level.FINEST)) {
        LOG.finest("String_Node_Str");
      }
      continue;
    }
    final List<Chunk> chunksInBin=bin.getChunkList();
    if (chunksInBin.isEmpty()) {
      if (LOG.isLoggable(Level.FINEST)) {
        LOG.finest("String_Node_Str");
      }
      continue;
    }
    if (currentShard == null) {
      if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("String_Node_Str" + index.getFirstLocusInBin(bin));
      }
      currentShard=new BAMShard(filePath,reference.getSequenceName(),index.getFirstLocusInBin(bin));
    }
    currentShard.addBin(chunksInBin,index.getLastLocusInBin(bin));
    if (LOG.isLoggable(Level.FINE)) {
      LOG.fine("String_Node_Str" + index.getLastLocusInBin(bin));
    }
    if (shardingPolicy.shardBigEnough(currentShard)) {
      LOG.info("String_Node_Str" + currentShard.sizeInLoci() + "String_Node_Str"+ currentShard.approximateSizeInBytes()+ "String_Node_Str");
      c.output(currentShard.finalize(index,-1));
      currentShard=null;
    }
  }
  if (currentShard != null) {
    LOG.info("String_Node_Str" + currentShard.sizeInLoci() + "String_Node_Str"+ currentShard.approximateSizeInBytes()+ "String_Node_Str");
    c.output(currentShard.finalize(index,(int)contig.end));
  }
}

Fixed version (ground truth):
void createShardsForReference(SAMSequenceRecord reference,Contig contig){
  final BitSet overlappingBins=GenomicIndexUtil.regionToBins((int)contig.start,(int)contig.end);
  if (overlappingBins == null) {
    LOG.warning("String_Node_Str" + contig.start + "String_Node_Str"+ contig.end);
    return;
  }
  BAMShard currentShard=null;
  for (int binIndex=overlappingBins.nextSetBit(0); binIndex >= 0; binIndex=overlappingBins.nextSetBit(binIndex + 1)) {
    final Bin bin=index.getBinData(reference.getSequenceIndex(),binIndex);
    if (bin == null) {
      continue;
    }
    if (LOG.isLoggable(Level.FINE)) {
      LOG.fine("String_Node_Str" + index.getFirstLocusInBin(bin) + "String_Node_Str"+ index.getLastLocusInBin(bin));
    }
    if (index.getLevelForBin(bin) != (GenomicIndexUtil.LEVEL_STARTS.length - 1)) {
      if (LOG.isLoggable(Level.FINEST)) {
        LOG.finest("String_Node_Str");
      }
      continue;
    }
    final List<Chunk> chunksInBin=bin.getChunkList();
    if (chunksInBin.isEmpty()) {
      if (LOG.isLoggable(Level.FINEST)) {
        LOG.finest("String_Node_Str");
      }
      continue;
    }
    if (currentShard == null) {
      int startLocus=Math.max(index.getFirstLocusInBin(bin),(int)contig.start);
      if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("String_Node_Str" + startLocus);
      }
      currentShard=new BAMShard(filePath,reference.getSequenceName(),startLocus);
    }
    currentShard.addBin(chunksInBin,index.getLastLocusInBin(bin));
    if (LOG.isLoggable(Level.FINE)) {
      LOG.fine("String_Node_Str" + index.getLastLocusInBin(bin));
    }
    if (shardingPolicy.shardBigEnough(currentShard)) {
      LOG.info("String_Node_Str" + currentShard.sizeInLoci() + "String_Node_Str"+ currentShard.approximateSizeInBytes()+ "String_Node_Str");
      c.output(currentShard.finalize(index,Math.min(index.getLastLocusInBin(bin),(int)contig.end)));
      currentShard=null;
    }
  }
  if (currentShard != null) {
    LOG.info("String_Node_Str" + currentShard.sizeInLoci() + "String_Node_Str"+ currentShard.approximateSizeInBytes()+ "String_Node_Str");
    c.output(currentShard.finalize(index,(int)contig.end));
  }
}