Program: 30608
Project: 30608
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;
  final DecimalFormat format=new DecimalFormat("String_Node_Str");
  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(format.format(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(format.format(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(format.format(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;
  final DecimalFormat format=new DecimalFormat("String_Node_Str");
  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(format.format(index++)));
      split=new IntervalList(list.getHeader());
      splitLength=0;
    }
 else {
      int consumed=0;
      while (projectedSize > idealSplitLength && index < SCATTER_COUNT) {
        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(format.format(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(format.format(index)));
  return totalIntervals;
}