Program: 89954
Project: 89954
Buggy source:
private void processReservations(Ec2InstanceReservationPrice.ReservationUtilization utilization){
  if (config.reservationService.getTagGroups(utilization).size() == 0)   return;
  ReadWriteData usageData=usageDataByProduct.get(null);
  ReadWriteData costData=costDataByProduct.get(null);
  Map<Account,List<Account>> reservationAccounts=config.accountService.getReservationAccounts();
  Set<Account> reservationOwners=reservationAccounts.keySet();
  Map<Account,List<Account>> reservationBorrowers=Maps.newHashMap();
  for (  Account account : reservationAccounts.keySet()) {
    List<Account> list=reservationAccounts.get(account);
    for (    Account borrowingAccount : list) {
      if (borrowingAccount.name.equals(account.name))       continue;
      List<Account> from=reservationBorrowers.get(borrowingAccount);
      if (from == null) {
        from=Lists.newArrayList();
        reservationBorrowers.put(borrowingAccount,from);
      }
      from.add(account);
    }
  }
  Set<TagGroup> toMarkOwners=Sets.newTreeSet();
  for (  TagGroup tagGroup : config.reservationService.getTagGroups(utilization)) {
    for (int i=0; i < usageData.getNum(); i++) {
      Map<TagGroup,Double> usageMap=usageData.getData(i);
      Map<TagGroup,Double> costMap=costData.getData(i);
      Double existing=usageMap.get(tagGroup);
      double value=existing == null ? 0 : existing;
      ReservationService.ReservationInfo reservation=config.reservationService.getReservation(startMilli + i * AwsUtils.hourMillis,tagGroup,utilization);
      double reservedUsed=Math.min(value,reservation.capacity);
      double reservedUnused=reservation.capacity - reservedUsed;
      double bonusReserved=value > reservation.capacity ? value - reservation.capacity : 0;
      if (reservedUsed > 0 || existing != null) {
        usageMap.put(tagGroup,reservedUsed);
        costMap.put(tagGroup,reservedUsed * reservation.reservationHourlyCost);
      }
      if (reservedUnused > 0) {
        TagGroup unusedTagGroup=new TagGroup(tagGroup.account,tagGroup.region,tagGroup.zone,tagGroup.product,Operation.getUnusedInstances(utilization),tagGroup.usageType,null);
        usageMap.put(unusedTagGroup,reservedUnused);
        costMap.put(unusedTagGroup,reservedUnused * reservation.reservationHourlyCost);
      }
      if (bonusReserved > 0) {
        TagGroup bonusTagGroup=new TagGroup(tagGroup.account,tagGroup.region,tagGroup.zone,tagGroup.product,Operation.getBonusReservedInstances(utilization),tagGroup.usageType,null);
        usageMap.put(bonusTagGroup,bonusReserved);
        costMap.put(bonusTagGroup,bonusReserved * reservation.reservationHourlyCost);
      }
      if (reservation.capacity > 0) {
        TagGroup upfrontTagGroup=new TagGroup(tagGroup.account,tagGroup.region,tagGroup.zone,tagGroup.product,Operation.getUpfrontAmortized(utilization),tagGroup.usageType,null);
        costMap.put(upfrontTagGroup,reservation.capacity * reservation.upfrontAmortized);
      }
    }
    toMarkOwners.add(new TagGroup(tagGroup.account,tagGroup.region,tagGroup.zone,tagGroup.product,Operation.getReservedInstances(utilization),tagGroup.usageType,null));
  }
  Set<TagGroup> toMarkBorrowing=Sets.newTreeSet();
  for (  TagGroup tagGroup : usageData.getTagGroups()) {
    if (tagGroup.resourceGroup == null && tagGroup.product == Product.ec2_instance && (!toMarkOwners.contains(tagGroup) && tagGroup.operation == Operation.getReservedInstances(utilization) || toMarkOwners.contains(tagGroup) && tagGroup.operation == Operation.getBonusReservedInstances(utilization))) {
      toMarkBorrowing.add(tagGroup);
    }
  }
  for (  TagGroup tagGroup : toMarkBorrowing) {
    for (int i=0; i < usageData.getNum(); i++) {
      Map<TagGroup,Double> usageMap=usageData.getData(i);
      Map<TagGroup,Double> costMap=costData.getData(i);
      borrow(i,startMilli + i * AwsUtils.hourMillis,usageMap,costMap,reservationBorrowers.get(tagGroup.account),tagGroup,utilization,reservationOwners.contains(tagGroup.account));
    }
  }
}

Fixed version (ground truth):
private void processReservations(Ec2InstanceReservationPrice.ReservationUtilization utilization){
  if (config.reservationService.getTagGroups(utilization).size() == 0)   return;
  ReadWriteData usageData=usageDataByProduct.get(null);
  ReadWriteData costData=costDataByProduct.get(null);
  Map<Account,List<Account>> reservationAccounts=config.accountService.getReservationAccounts();
  Set<Account> reservationOwners=reservationAccounts.keySet();
  Map<Account,List<Account>> reservationBorrowers=Maps.newHashMap();
  for (  Account account : reservationAccounts.keySet()) {
    List<Account> list=reservationAccounts.get(account);
    for (    Account borrowingAccount : list) {
      if (borrowingAccount.name.equals(account.name))       continue;
      List<Account> from=reservationBorrowers.get(borrowingAccount);
      if (from == null) {
        from=Lists.newArrayList();
        reservationBorrowers.put(borrowingAccount,from);
      }
      from.add(account);
    }
  }
  Set<TagGroup> toMarkOwners=Sets.newTreeSet();
  for (  TagGroup tagGroup : config.reservationService.getTagGroups(utilization)) {
    for (int i=0; i < usageData.getNum(); i++) {
      Map<TagGroup,Double> usageMap=usageData.getData(i);
      Map<TagGroup,Double> costMap=costData.getData(i);
      Double existing=usageMap.get(tagGroup);
      double value=existing == null ? 0 : existing;
      ReservationService.ReservationInfo reservation=config.reservationService.getReservation(startMilli + i * AwsUtils.hourMillis,tagGroup,utilization);
      double reservedUsed=Math.min(value,reservation.capacity);
      double reservedUnused=reservation.capacity - reservedUsed;
      double bonusReserved=value > reservation.capacity ? value - reservation.capacity : 0;
      if (reservedUsed > 0 || existing != null) {
        usageMap.put(tagGroup,reservedUsed);
        costMap.put(tagGroup,reservedUsed * reservation.reservationHourlyCost);
      }
      if (reservedUnused > 0) {
        TagGroup unusedTagGroup=new TagGroup(tagGroup.account,tagGroup.region,tagGroup.zone,tagGroup.product,Operation.getUnusedInstances(utilization),tagGroup.usageType,null);
        usageMap.put(unusedTagGroup,reservedUnused);
        costMap.put(unusedTagGroup,reservedUnused * reservation.reservationHourlyCost);
      }
      if (bonusReserved > 0) {
        TagGroup bonusTagGroup=new TagGroup(tagGroup.account,tagGroup.region,tagGroup.zone,tagGroup.product,Operation.getBonusReservedInstances(utilization),tagGroup.usageType,null);
        usageMap.put(bonusTagGroup,bonusReserved);
        costMap.put(bonusTagGroup,bonusReserved * reservation.reservationHourlyCost);
      }
      if (reservation.capacity > 0) {
        TagGroup upfrontTagGroup=new TagGroup(tagGroup.account,tagGroup.region,tagGroup.zone,tagGroup.product,Operation.getUpfrontAmortized(utilization),tagGroup.usageType,null);
        costMap.put(upfrontTagGroup,reservation.capacity * reservation.upfrontAmortized);
      }
    }
    toMarkOwners.add(new TagGroup(tagGroup.account,tagGroup.region,tagGroup.zone,tagGroup.product,Operation.getReservedInstances(utilization),tagGroup.usageType,null));
  }
  Set<TagGroup> toMarkBorrowing=Sets.newTreeSet();
  for (  TagGroup tagGroup : usageData.getTagGroups()) {
    if (tagGroup.resourceGroup == null && tagGroup.product == Product.ec2_instance && (tagGroup.operation == Operation.getReservedInstances(utilization) && !toMarkOwners.contains(tagGroup) || tagGroup.operation == Operation.getBonusReservedInstances(utilization))) {
      toMarkBorrowing.add(tagGroup);
    }
  }
  for (  TagGroup tagGroup : toMarkBorrowing) {
    for (int i=0; i < usageData.getNum(); i++) {
      Map<TagGroup,Double> usageMap=usageData.getData(i);
      Map<TagGroup,Double> costMap=costData.getData(i);
      borrow(i,startMilli + i * AwsUtils.hourMillis,usageMap,costMap,reservationBorrowers.get(tagGroup.account),tagGroup,utilization,reservationOwners.contains(tagGroup.account));
    }
  }
}