Program: 89961
Project: 89961
Buggy source:
private MimeBodyPart constructEmail(int index,ApplicationGroup appGroup,StringBuilder body) throws IOException, MessagingException {
  if (index == 0 && !StringUtils.isEmpty(headerNote))   body.append(headerNote);
  numberFormatter.setMaximumFractionDigits(1);
  numberFormatter.setMinimumFractionDigits(1);
  File file=createImage(appGroup);
  DateTime end=new DateTime(DateTimeZone.UTC).withDayOfWeek(1).withMillisOfDay(0);
  String link=getLink("String_Node_Str",ConsolidateType.hourly,appGroup,accounts,regions,end.minusWeeks(numWeeks),end);
  body.append(String.format("String_Node_Str",link,appGroup.getDisplayName()));
  body.append("String_Node_Str");
  body.append("String_Node_Str");
  for (int i=0; i <= accounts.size(); i++) {
    int cols=i == accounts.size() ? 1 : regions.size();
    String accName=i == accounts.size() ? "String_Node_Str" : accounts.get(i).name;
    body.append(String.format("String_Node_Str",cols)).append(accName).append("String_Node_Str");
  }
  body.append("String_Node_Str");
  body.append("String_Node_Str");
  for (int i=0; i < accounts.size(); i++) {
    boolean first=true;
    for (    Region region : regions) {
      body.append("String_Node_Str" + (first ? "String_Node_Str" : "String_Node_Str") + "String_Node_Str").append(region.name).append("String_Node_Str");
      first=false;
    }
  }
  body.append("String_Node_Str");
  Map<String,Double> costs=Maps.newHashMap();
  Interval interval=new Interval(end.minusWeeks(numWeeks),end);
  double[] total=new double[numWeeks];
  for (  Product product : products) {
    List<ResourceGroup> resourceGroups=getResourceGroups(appGroup,product);
    if (resourceGroups.size() == 0)     continue;
    DataManager dataManager=config.managers.getCostManager(product,ConsolidateType.weekly);
    for (int i=0; i < accounts.size(); i++) {
      List<Account> accountList=Lists.newArrayList(accounts.get(i));
      TagLists tagLists=new TagLists(accountList,regions,null,Lists.newArrayList(product),null,null,resourceGroups);
      Map<Tag,double[]> data=dataManager.getData(interval,tagLists,TagType.Region,AggregateType.none,false);
      for (      Tag tag : data.keySet()) {
        for (int week=0; week < numWeeks; week++) {
          String key=accounts.get(i) + "String_Node_Str" + tag+ "String_Node_Str"+ week;
          if (costs.containsKey(key))           costs.put(key,data.get(tag)[week] + costs.get(key));
 else           costs.put(key,data.get(tag)[week]);
          total[week]+=data.get(tag)[week];
        }
      }
    }
  }
  boolean firstLine=true;
  DateTime currentWeekEnd=end;
  for (int week=0; week < numWeeks; week++) {
    String weekStr;
    if (week == 0)     weekStr="String_Node_Str";
 else     weekStr=week + "String_Node_Str";
    String background=week % 2 == 1 ? "String_Node_Str" : "String_Node_Str";
    body.append(String.format("String_Node_Str",background,weekStr,formatter.print(currentWeekEnd.minusWeeks(1)).substring(5),formatter.print(currentWeekEnd).substring(5)));
    for (int i=0; i < accounts.size(); i++) {
      Account account=accounts.get(i);
      for (int j=0; j < regions.size(); j++) {
        Region region=regions.get(j);
        String key=account + "String_Node_Str" + region+ "String_Node_Str"+ week;
        double cost=costs.get(key) == null ? 0 : costs.get(key);
        Double lastCost=week == numWeeks - 1 ? null : costs.get(account + "String_Node_Str" + region+ "String_Node_Str"+ (week + 1));
        link=getLink("String_Node_Str",ConsolidateType.daily,appGroup,Lists.newArrayList(account),Lists.newArrayList(region),currentWeekEnd.minusWeeks(1),currentWeekEnd);
        body.append(getValueCell(cost,lastCost,link,firstLine));
      }
    }
    link=getLink("String_Node_Str",ConsolidateType.daily,appGroup,accounts,regions,currentWeekEnd.minusWeeks(1),currentWeekEnd);
    body.append(getValueCell(total[week],week == numWeeks - 1 ? null : total[week + 1],link,firstLine));
    body.append("String_Node_Str");
    firstLine=false;
    currentWeekEnd=currentWeekEnd.minusWeeks(1);
  }
  body.append("String_Node_Str");
  numberFormatter.setMaximumFractionDigits(0);
  numberFormatter.setMinimumFractionDigits(0);
  if (!StringUtils.isEmpty(throughputMetrics))   body.append(throughputMetrics);
  body.append("String_Node_Str" + index + "String_Node_Str");
  for (  Map.Entry<String,List<String>> entry : appGroup.data.entrySet()) {
    String product=entry.getKey();
    List<String> selected=entry.getValue();
    if (selected == null || selected.size() == 0)     continue;
    link=getLink("String_Node_Str",ConsolidateType.hourly,appGroup,accounts,regions,end.minusWeeks(numWeeks),end);
    body.append(String.format("String_Node_Str",product,link,appGroup.getDisplayName()));
    for (    String name : selected)     body.append("String_Node_Str").append(name).append("String_Node_Str");
  }
  body.append("String_Node_Str");
  MimeBodyPart mimeBodyPart=new MimeBodyPart();
  mimeBodyPart.setFileName(file.getName());
  DataSource ds=new ByteArrayDataSource(new FileInputStream(file),"String_Node_Str");
  mimeBodyPart.setDataHandler(new DataHandler(ds));
  mimeBodyPart.setHeader("String_Node_Str","String_Node_Str" + index + "String_Node_Str");
  mimeBodyPart.setHeader("String_Node_Str","String_Node_Str");
  mimeBodyPart.setDisposition(MimeBodyPart.INLINE);
  file.delete();
  return mimeBodyPart;
}

Fixed version (ground truth):
private MimeBodyPart constructEmail(int index,ApplicationGroup appGroup,StringBuilder body) throws IOException, MessagingException {
  if (index == 0 && !StringUtils.isEmpty(headerNote))   body.append(headerNote);
  numberFormatter.setMaximumFractionDigits(1);
  numberFormatter.setMinimumFractionDigits(1);
  File file=createImage(appGroup);
  if (file == null)   return null;
  DateTime end=new DateTime(DateTimeZone.UTC).withDayOfWeek(1).withMillisOfDay(0);
  String link=getLink("String_Node_Str",ConsolidateType.hourly,appGroup,accounts,regions,end.minusWeeks(numWeeks),end);
  body.append(String.format("String_Node_Str",link,appGroup.getDisplayName()));
  body.append("String_Node_Str");
  body.append("String_Node_Str");
  for (int i=0; i <= accounts.size(); i++) {
    int cols=i == accounts.size() ? 1 : regions.size();
    String accName=i == accounts.size() ? "String_Node_Str" : accounts.get(i).name;
    body.append(String.format("String_Node_Str",cols)).append(accName).append("String_Node_Str");
  }
  body.append("String_Node_Str");
  body.append("String_Node_Str");
  for (int i=0; i < accounts.size(); i++) {
    boolean first=true;
    for (    Region region : regions) {
      body.append("String_Node_Str" + (first ? "String_Node_Str" : "String_Node_Str") + "String_Node_Str").append(region.name).append("String_Node_Str");
      first=false;
    }
  }
  body.append("String_Node_Str");
  Map<String,Double> costs=Maps.newHashMap();
  Interval interval=new Interval(end.minusWeeks(numWeeks),end);
  double[] total=new double[numWeeks];
  for (  Product product : products) {
    List<ResourceGroup> resourceGroups=getResourceGroups(appGroup,product);
    if (resourceGroups.size() == 0)     continue;
    DataManager dataManager=config.managers.getCostManager(product,ConsolidateType.weekly);
    for (int i=0; i < accounts.size(); i++) {
      List<Account> accountList=Lists.newArrayList(accounts.get(i));
      TagLists tagLists=new TagLists(accountList,regions,null,Lists.newArrayList(product),null,null,resourceGroups);
      Map<Tag,double[]> data=dataManager.getData(interval,tagLists,TagType.Region,AggregateType.none,false);
      for (      Tag tag : data.keySet()) {
        for (int week=0; week < numWeeks; week++) {
          String key=accounts.get(i) + "String_Node_Str" + tag+ "String_Node_Str"+ week;
          if (costs.containsKey(key))           costs.put(key,data.get(tag)[week] + costs.get(key));
 else           costs.put(key,data.get(tag)[week]);
          total[week]+=data.get(tag)[week];
        }
      }
    }
  }
  boolean firstLine=true;
  DateTime currentWeekEnd=end;
  for (int week=numWeeks - 1; week >= 0; week--) {
    String weekStr;
    if (week == numWeeks - 1)     weekStr="String_Node_Str";
 else     weekStr=(numWeeks - week - 1) + "String_Node_Str";
    String background=week % 2 == 1 ? "String_Node_Str" : "String_Node_Str";
    body.append(String.format("String_Node_Str",background,weekStr,formatter.print(currentWeekEnd.minusWeeks(1)).substring(5),formatter.print(currentWeekEnd).substring(5)));
    for (int i=0; i < accounts.size(); i++) {
      Account account=accounts.get(i);
      for (int j=0; j < regions.size(); j++) {
        Region region=regions.get(j);
        String key=account + "String_Node_Str" + region+ "String_Node_Str"+ week;
        double cost=costs.get(key) == null ? 0 : costs.get(key);
        Double lastCost=week == 0 ? null : costs.get(account + "String_Node_Str" + region+ "String_Node_Str"+ (week - 1));
        link=getLink("String_Node_Str",ConsolidateType.daily,appGroup,Lists.newArrayList(account),Lists.newArrayList(region),currentWeekEnd.minusWeeks(1),currentWeekEnd);
        body.append(getValueCell(cost,lastCost,link,firstLine));
      }
    }
    link=getLink("String_Node_Str",ConsolidateType.daily,appGroup,accounts,regions,currentWeekEnd.minusWeeks(1),currentWeekEnd);
    body.append(getValueCell(total[week],week == 0 ? null : total[week - 1],link,firstLine));
    body.append("String_Node_Str");
    firstLine=false;
    currentWeekEnd=currentWeekEnd.minusWeeks(1);
  }
  body.append("String_Node_Str");
  numberFormatter.setMaximumFractionDigits(0);
  numberFormatter.setMinimumFractionDigits(0);
  if (!StringUtils.isEmpty(throughputMetrics))   body.append(throughputMetrics);
  body.append("String_Node_Str" + index + "String_Node_Str");
  for (  Map.Entry<String,List<String>> entry : appGroup.data.entrySet()) {
    String product=entry.getKey();
    List<String> selected=entry.getValue();
    if (selected == null || selected.size() == 0)     continue;
    link=getLink("String_Node_Str",ConsolidateType.hourly,appGroup,accounts,regions,end.minusWeeks(numWeeks),end);
    body.append(String.format("String_Node_Str",getResourceGroupsDisplayName(product),link,appGroup.getDisplayName()));
    for (    String name : selected)     body.append("String_Node_Str").append(name).append("String_Node_Str");
  }
  body.append("String_Node_Str");
  MimeBodyPart mimeBodyPart=new MimeBodyPart();
  mimeBodyPart.setFileName(file.getName());
  DataSource ds=new ByteArrayDataSource(new FileInputStream(file),"String_Node_Str");
  mimeBodyPart.setDataHandler(new DataHandler(ds));
  mimeBodyPart.setHeader("String_Node_Str","String_Node_Str" + index + "String_Node_Str");
  mimeBodyPart.setHeader("String_Node_Str","String_Node_Str");
  mimeBodyPart.setDisposition(MimeBodyPart.INLINE);
  file.delete();
  return mimeBodyPart;
}