Program: 30606
Project: 30606
Buggy source:
/** 
 * Method to scatter an interval list by locus.
 * @param list  The list of intervals to scatter
 * @return the number of intervals across the scattered lists (which may differ from the inputas some may have been split)
 */
private int scatterIntervals(final IntervalList list){
  final long idealSplitLength=Math.max((long)Math.floor(list.getUniqueBaseCount() / (1.0 * SCATTER_COUNT)),1);
  int splitLength=0;
  IntervalList split=new IntervalList(list.getHeader());
  int index=1;
  final Iterator<Interval> it=list.iterator();
  int totalIntervals=0;
  while (it.hasNext() && index < SCATTER_COUNT) {
    final Interval interval=it.next();
    final int projectedSize=splitLength + interval.length();
    if (projectedSize < idealSplitLength) {
      split.add(interval);
      totalIntervals++;
      splitLength+=interval.length();
    }
 else     if (projectedSize == idealSplitLength) {
      split.add(interval);
      totalIntervals++;
      split.write(createDirectoryAndGetScatterFile(index++));
      split=new IntervalList(list.getHeader());
      splitLength=0;
    }
 else {
      final int diff=(int)(idealSplitLength - splitLength);
      final Interval firstHalf=new Interval(interval.getSequence(),interval.getStart(),interval.getStart() + diff - 1,interval.isNegativeStrand(),interval.getName());
      split.add(firstHalf);
      totalIntervals++;
      split.write(createDirectoryAndGetScatterFile(index++));
      split=new IntervalList(list.getHeader());
      final Interval secondHalf=new Interval(interval.getSequence(),interval.getStart() + diff,interval.getEnd(),interval.isNegativeStrand(),interval.getName());
      split.add(secondHalf);
      totalIntervals++;
      splitLength=secondHalf.length();
    }
  }
  while (it.hasNext()) {
    split.add(it.next());
    totalIntervals++;
  }
  split.write(createDirectoryAndGetScatterFile(index));
  return totalIntervals;
}

Fixed version (ground truth):
/** 
 * Method to scatter an interval list by locus.
 * @param list  The list of intervals to scatter
 * @return the number of intervals across the scattered lists (which may differ from the inputas some may have been split)
 */
private int scatterIntervals(final IntervalList list){
  final long idealSplitLength=Math.max((long)Math.floor(list.getUniqueBaseCount() / (1.0 * SCATTER_COUNT)),1);
  int splitLength=0;
  IntervalList split=new IntervalList(list.getHeader());
  int index=1;
  final Iterator<Interval> it=list.iterator();
  int totalIntervals=0;
  while (it.hasNext() && index < SCATTER_COUNT) {
    final Interval interval=it.next();
    int projectedSize=splitLength + interval.length();
    if (projectedSize < idealSplitLength) {
      split.add(interval);
      totalIntervals++;
      splitLength+=interval.length();
    }
 else     if (projectedSize == idealSplitLength) {
      split.add(interval);
      totalIntervals++;
      split.write(createDirectoryAndGetScatterFile(index++));
      split=new IntervalList(list.getHeader());
      splitLength=0;
    }
 else {
      int consumed=0;
      while (projectedSize > idealSplitLength) {
        final int amountToConsume=(int)(idealSplitLength - splitLength);
        final Interval partial=new Interval(interval.getSequence(),interval.getStart() + consumed,interval.getStart() + consumed + amountToConsume - 1,interval.isNegativeStrand(),interval.getName());
        split.add(partial);
        totalIntervals++;
        split.write(createDirectoryAndGetScatterFile(index++));
        split=new IntervalList(list.getHeader());
        consumed+=amountToConsume;
        splitLength=0;
        projectedSize=interval.length() - consumed;
      }
      if (projectedSize > 0) {
        final Interval remainder=new Interval(interval.getSequence(),interval.getStart() + consumed,interval.getEnd(),interval.isNegativeStrand(),interval.getName());
        split.add(remainder);
        totalIntervals++;
        splitLength=remainder.length();
      }
    }
  }
  while (it.hasNext()) {
    split.add(it.next());
    totalIntervals++;
  }
  split.write(createDirectoryAndGetScatterFile(index));
  return totalIntervals;
}