Program: 105191
Project: 105191
Buggy source:
@Override public QuotaBalanceResponse createQuotaBalanceResponse(List<QuotaBalanceVO> quotaBalance,Date startDate,Date endDate){
  if (quotaBalance == null || quotaBalance.isEmpty()) {
    new InvalidParameterValueException("String_Node_Str");
  }
  Collections.sort(quotaBalance,new Comparator<QuotaBalanceVO>(){
    public int compare(    QuotaBalanceVO o1,    QuotaBalanceVO o2){
      return o2.getUpdatedOn().compareTo(o1.getUpdatedOn());
    }
  }
);
  boolean have_balance_entries=false;
  for (Iterator<QuotaBalanceVO> it=quotaBalance.iterator(); it.hasNext(); ) {
    QuotaBalanceVO entry=it.next();
    if (entry.getCreditsId() > 0) {
      have_balance_entries=true;
      break;
    }
  }
  if (have_balance_entries) {
    ListIterator<QuotaBalanceVO> li=quotaBalance.listIterator(quotaBalance.size());
    while (li.hasPrevious()) {
      QuotaBalanceVO entry=li.previous();
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + entry);
      }
      if (entry.getCreditsId() > 0) {
        li.remove();
      }
 else {
        break;
      }
    }
  }
  int quota_activity=quotaBalance.size();
  QuotaBalanceResponse resp=new QuotaBalanceResponse();
  BigDecimal lastCredits=new BigDecimal(0);
  boolean consecutive=true;
  for (Iterator<QuotaBalanceVO> it=quotaBalance.iterator(); it.hasNext(); ) {
    QuotaBalanceVO entry=it.next();
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + entry);
    }
    if (entry.getCreditsId() > 0) {
      if (consecutive) {
        lastCredits=lastCredits.add(entry.getCreditBalance());
      }
      resp.addCredits(entry);
      it.remove();
    }
 else {
      consecutive=false;
    }
  }
  if (quota_activity > 0 && quotaBalance.size() > 0) {
    QuotaBalanceVO startItem=quotaBalance.get(quotaBalance.size() - 1);
    QuotaBalanceVO endItem=quotaBalance.get(0);
    resp.setStartDate(startDate);
    resp.setStartQuota(startItem.getCreditBalance());
    resp.setEndDate(endDate);
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + startItem);
      s_logger.debug("String_Node_Str" + endItem);
    }
    resp.setEndQuota(endItem.getCreditBalance().add(lastCredits));
  }
 else   if (quota_activity > 0) {
    resp.setStartDate(startDate);
    resp.setStartQuota(new BigDecimal(0));
    resp.setEndDate(endDate);
    resp.setEndQuota(new BigDecimal(0).add(lastCredits));
  }
 else {
    resp.setStartDate(startDate);
    resp.setEndDate(endDate);
    resp.setStartQuota(new BigDecimal(0));
    resp.setEndQuota(new BigDecimal(0));
  }
  resp.setCurrency(QuotaConfig.QuotaCurrencySymbol.value());
  resp.setObjectName("String_Node_Str");
  return resp;
}

Fixed version (ground truth):
@Override public QuotaBalanceResponse createQuotaBalanceResponse(List<QuotaBalanceVO> quotaBalance,Date startDate,Date endDate){
  if (quotaBalance == null || quotaBalance.isEmpty()) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  Collections.sort(quotaBalance,new Comparator<QuotaBalanceVO>(){
    public int compare(    QuotaBalanceVO o1,    QuotaBalanceVO o2){
      o1=o1 == null ? new QuotaBalanceVO() : o1;
      o2=o2 == null ? new QuotaBalanceVO() : o2;
      return o2.getUpdatedOn().compareTo(o1.getUpdatedOn());
    }
  }
);
  boolean have_balance_entries=false;
  for (Iterator<QuotaBalanceVO> it=quotaBalance.iterator(); it.hasNext(); ) {
    QuotaBalanceVO entry=it.next();
    if (entry.getCreditsId() > 0) {
      have_balance_entries=true;
      break;
    }
  }
  if (have_balance_entries) {
    ListIterator<QuotaBalanceVO> li=quotaBalance.listIterator(quotaBalance.size());
    while (li.hasPrevious()) {
      QuotaBalanceVO entry=li.previous();
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + entry);
      }
      if (entry.getCreditsId() > 0) {
        li.remove();
      }
 else {
        break;
      }
    }
  }
  int quota_activity=quotaBalance.size();
  QuotaBalanceResponse resp=new QuotaBalanceResponse();
  BigDecimal lastCredits=new BigDecimal(0);
  boolean consecutive=true;
  for (Iterator<QuotaBalanceVO> it=quotaBalance.iterator(); it.hasNext(); ) {
    QuotaBalanceVO entry=it.next();
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + entry);
    }
    if (entry.getCreditsId() > 0) {
      if (consecutive) {
        lastCredits=lastCredits.add(entry.getCreditBalance());
      }
      resp.addCredits(entry);
      it.remove();
    }
 else {
      consecutive=false;
    }
  }
  if (quota_activity > 0 && quotaBalance.size() > 0) {
    QuotaBalanceVO startItem=quotaBalance.get(quotaBalance.size() - 1);
    QuotaBalanceVO endItem=quotaBalance.get(0);
    resp.setStartDate(startDate);
    resp.setStartQuota(startItem.getCreditBalance());
    resp.setEndDate(endDate);
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + startItem);
      s_logger.debug("String_Node_Str" + endItem);
    }
    resp.setEndQuota(endItem.getCreditBalance().add(lastCredits));
  }
 else   if (quota_activity > 0) {
    resp.setStartDate(startDate);
    resp.setStartQuota(new BigDecimal(0));
    resp.setEndDate(endDate);
    resp.setEndQuota(new BigDecimal(0).add(lastCredits));
  }
 else {
    resp.setStartDate(startDate);
    resp.setEndDate(endDate);
    resp.setStartQuota(new BigDecimal(0));
    resp.setEndQuota(new BigDecimal(0));
  }
  resp.setCurrency(QuotaConfig.QuotaCurrencySymbol.value());
  resp.setObjectName("String_Node_Str");
  return resp;
}