Program: 146267
Project: 146267
Buggy source:
public BinCard generateBinCard(Commodity commodity) throws Exception {
  List<String> receiveSources=Arrays.asList(context.getString(R.string.lga),context.getString(R.string.zonal_store),context.getString(R.string.others));
  Date today=new Date();
  Date tomorrow=DateUtil.addDayOfMonth(today,1);
  Date startDate=DateUtil.addDayOfMonth(today,-31);
  List<ReceiveItem> receiveItems=GenericService.getItems(commodity,startDate,today,Receive.class,ReceiveItem.class,context);
  List<DispensingItem> dispensingItems=GenericService.getItems(commodity,startDate,today,Dispensing.class,DispensingItem.class,context);
  List<LossItem> lossItems=GenericService.getItems(commodity,startDate,today,Loss.class,LossItem.class,context);
  List<StockItemSnapshot> stockItemSnapshots=stockItemSnapshotService.get(commodity,startDate,today);
  List<Adjustment> adjustments=adjustmentService.getAdjustments(commodity,startDate,today);
  int previousDaysClosingStock=stockItemSnapshotService.getLatestStock(commodity,startDate,false);
  List<BinCardItem> binCardItems=new ArrayList<>();
  Date date=startDate;
  while (date.before(tomorrow)) {
    List<BinCardItem> binCardItemsForDate=new ArrayList<>();
    int quantityDispensed=GenericService.getTotal(date,dispensingItems);
    int quantityLost=GenericService.getTotal(date,lossItems);
    int closingBalance=previousDaysClosingStock;
    List<ReceivedBySource> receivedBySources=new ArrayList<>();
    for (    final String source : receiveSources) {
      List<ReceiveItem> receiveItemsForDate=getItemsByDate(date,receiveItems);
      List<ReceiveItem> sourceReceiveItems=FluentIterable.from(receiveItemsForDate).filter(new Predicate<ReceiveItem>(){
        @Override public boolean apply(        ReceiveItem input){
          return input.getReceive().getSource().equalsIgnoreCase(source);
        }
      }
).toList();
      int quantityReceived=0;
      if (sourceReceiveItems != null) {
        for (        ReceiveItem item : sourceReceiveItems) {
          quantityReceived+=item.getQuantity();
        }
      }
      if (quantityReceived > 0) {
        receivedBySources.add(new ReceivedBySource(quantityReceived,source));
      }
    }
    int quantitySentToAnotherFacility=adjustmentService.totalAdjustment(commodity,adjustments,date,AdjustmentReason.SENT_TO_ANOTHER_FACILITY);
    int quantityReceivedFromAnotherFacility=adjustmentService.totalAdjustment(commodity,adjustments,date,AdjustmentReason.RECEIVED_FROM_ANOTHER_FACILITY);
    int quantityAdjusted=adjustmentService.totalAdjustment(commodity,adjustments,date,Arrays.asList(AdjustmentReason.PHYSICAL_COUNT,AdjustmentReason.RETURNED_TO_LGA));
    StockItemSnapshot dayStockItemSnapshot=stockItemSnapshotService.getSnapshot(date,stockItemSnapshots);
    if (dayStockItemSnapshot != null) {
      closingBalance=dayStockItemSnapshot.getQuantity();
    }
    if (quantityDispensed > 0) {
      binCardItemsForDate.add(new BinCardItem(date,"String_Node_Str",0,quantityDispensed,0,0,-1));
    }
    if (quantityLost > 0) {
      binCardItemsForDate.add(new BinCardItem(date,"String_Node_Str",0,0,quantityLost,0,-1));
    }
    if (quantityAdjusted > 0) {
      binCardItemsForDate.add(new BinCardItem(date,"String_Node_Str",0,0,0,quantityAdjusted,-1));
    }
    if (quantityReceivedFromAnotherFacility > 0) {
      binCardItemsForDate.add(new BinCardItem(date,"String_Node_Str",0,0,0,quantityReceivedFromAnotherFacility,-1));
    }
    if (quantitySentToAnotherFacility > 0) {
      binCardItemsForDate.add(new BinCardItem(date,"String_Node_Str",0,0,0,quantitySentToAnotherFacility,-1));
    }
    for (    ReceivedBySource source : receivedBySources) {
      binCardItemsForDate.add(new BinCardItem(date,source.getSource(),source.getQuantityReceived(),0,0,0,-1));
    }
    if (binCardItemsForDate.size() > 0) {
      binCardItemsForDate.get(binCardItemsForDate.size() - 1).setStockBalance(closingBalance);
    }
    binCardItems.addAll(binCardItemsForDate);
    previousDaysClosingStock=closingBalance;
    date=DateUtil.addDayOfMonth(date,1);
  }
  return new BinCard(commodity.getMinimumThreshold(),commodity.getMaximumThreshold(),binCardItems,commodity);
}

Fixed version (ground truth):
public BinCard generateBinCard(Commodity commodity) throws Exception {
  List<String> receiveSources=Arrays.asList(context.getString(R.string.lga),context.getString(R.string.zonal_store),context.getString(R.string.others));
  Date today=new Date();
  Date tomorrow=DateUtil.addDayOfMonth(today,1);
  Date startDate=DateUtil.addDayOfMonth(today,-31);
  List<ReceiveItem> receiveItems=GenericService.getItems(commodity,startDate,today,Receive.class,ReceiveItem.class,context);
  List<DispensingItem> dispensingItems=GenericService.getItems(commodity,startDate,today,Dispensing.class,DispensingItem.class,context);
  List<LossItem> lossItems=GenericService.getItems(commodity,startDate,today,Loss.class,LossItem.class,context);
  List<StockItemSnapshot> stockItemSnapshots=stockItemSnapshotService.get(commodity,startDate,today);
  List<Adjustment> adjustments=adjustmentService.getAdjustments(commodity,startDate,today);
  int previousDaysClosingStock=stockItemSnapshotService.getClosingBalance(commodity,startDate);
  List<BinCardItem> binCardItems=new ArrayList<>();
  Date date=startDate;
  while (date.before(tomorrow)) {
    List<BinCardItem> binCardItemsForDate=new ArrayList<>();
    int quantityDispensed=GenericService.getTotal(date,dispensingItems);
    int quantityLost=GenericService.getTotal(date,lossItems);
    int closingBalance=previousDaysClosingStock;
    List<ReceivedBySource> receivedBySources=new ArrayList<>();
    for (    final String source : receiveSources) {
      List<ReceiveItem> receiveItemsForDate=getItemsByDate(date,receiveItems);
      List<ReceiveItem> sourceReceiveItems=FluentIterable.from(receiveItemsForDate).filter(new Predicate<ReceiveItem>(){
        @Override public boolean apply(        ReceiveItem input){
          return input.getReceive().getSource().equalsIgnoreCase(source);
        }
      }
).toList();
      int quantityReceived=0;
      if (sourceReceiveItems != null) {
        for (        ReceiveItem item : sourceReceiveItems) {
          quantityReceived+=item.getQuantity();
        }
      }
      if (quantityReceived > 0) {
        receivedBySources.add(new ReceivedBySource(quantityReceived,source));
      }
    }
    int quantitySentToAnotherFacility=adjustmentService.totalAdjustment(commodity,adjustments,date,AdjustmentReason.SENT_TO_ANOTHER_FACILITY);
    int quantityReceivedFromAnotherFacility=adjustmentService.totalAdjustment(commodity,adjustments,date,AdjustmentReason.RECEIVED_FROM_ANOTHER_FACILITY);
    int quantityAdjusted=adjustmentService.totalAdjustment(commodity,adjustments,date,Arrays.asList(AdjustmentReason.PHYSICAL_COUNT,AdjustmentReason.RETURNED_TO_LGA));
    StockItemSnapshot dayStockItemSnapshot=stockItemSnapshotService.getSnapshot(date,stockItemSnapshots);
    if (dayStockItemSnapshot != null) {
      closingBalance=dayStockItemSnapshot.getQuantity();
    }
    if (quantityDispensed > 0) {
      binCardItemsForDate.add(new BinCardItem(date,"String_Node_Str",0,quantityDispensed,0,0,-1));
    }
    if (quantityLost > 0) {
      binCardItemsForDate.add(new BinCardItem(date,"String_Node_Str",0,0,quantityLost,0,-1));
    }
    if (quantityAdjusted > 0) {
      binCardItemsForDate.add(new BinCardItem(date,"String_Node_Str",0,0,0,quantityAdjusted,-1));
    }
    if (quantityReceivedFromAnotherFacility > 0) {
      binCardItemsForDate.add(new BinCardItem(date,"String_Node_Str",0,0,0,quantityReceivedFromAnotherFacility,-1));
    }
    if (quantitySentToAnotherFacility > 0) {
      binCardItemsForDate.add(new BinCardItem(date,"String_Node_Str",0,0,0,quantitySentToAnotherFacility,-1));
    }
    for (    ReceivedBySource source : receivedBySources) {
      binCardItemsForDate.add(new BinCardItem(date,source.getSource(),source.getQuantityReceived(),0,0,0,-1));
    }
    if (binCardItemsForDate.size() > 0) {
      binCardItemsForDate.get(binCardItemsForDate.size() - 1).setStockBalance(closingBalance);
    }
    binCardItems.addAll(binCardItemsForDate);
    previousDaysClosingStock=closingBalance;
    date=DateUtil.addDayOfMonth(date,1);
  }
  return new BinCard(commodity.getMinimumThreshold(),commodity.getMaximumThreshold(),binCardItems,commodity);
}