Program: 14424
Project: 14424
Buggy source:
@Override public ReportArtEntity generateReportArt(final ReportArtEntity report){
  log.debug("String_Node_Str");
  final Map<String,ReportingUser> users=Maps.newHashMap();
  final Map<String,String> accounts=Maps.newHashMap();
  final Map<String,InstanceUsageArtEntity> usageEntities=new HashMap<String,InstanceUsageArtEntity>();
  final Map<String,Long> instanceStartTimes=new HashMap<String,Long>();
  foreachInstanceCreateEvent(report.getEndMs(),new Predicate<ReportingInstanceCreateEvent>(){
    @Override public boolean apply(    final ReportingInstanceCreateEvent createEvent){
      if (!report.getZones().containsKey(createEvent.getAvailabilityZone())) {
        report.getZones().put(createEvent.getAvailabilityZone(),new AvailabilityZoneArtEntity());
      }
      AvailabilityZoneArtEntity zone=report.getZones().get(createEvent.getAvailabilityZone());
      final ReportingUser reportingUser=getUserById(users,createEvent.getUserId());
      if (reportingUser == null) {
        log.error("String_Node_Str" + createEvent.getUserId());
        return true;
      }
      final String accountName=getAccountNameById(accounts,reportingUser.getAccountId());
      if (accountName == null) {
        log.error("String_Node_Str" + reportingUser.getAccountId());
        return true;
      }
      if (!zone.getAccounts().containsKey(accountName)) {
        zone.getAccounts().put(accountName,new AccountArtEntity());
      }
      AccountArtEntity account=zone.getAccounts().get(accountName);
      if (!account.getUsers().containsKey(reportingUser.getName())) {
        account.getUsers().put(reportingUser.getName(),new UserArtEntity());
      }
      UserArtEntity user=account.getUsers().get(reportingUser.getName());
      if (!user.getInstances().containsKey(createEvent.getUuid())) {
        user.getInstances().put(createEvent.getUuid(),new InstanceArtEntity(createEvent.getInstanceType(),createEvent.getInstanceId()));
      }
      InstanceArtEntity instance=user.getInstances().get(createEvent.getUuid());
      instance.getUsage().addInstanceCnt(1);
      usageEntities.put(createEvent.getUuid(),instance.getUsage());
      instanceStartTimes.put(createEvent.getUuid(),createEvent.getTimestampMs());
      return true;
    }
  }
);
  final Map<InstanceMetricDimensionKey,MetricPrevData> prevDataMap=new HashMap<InstanceMetricDimensionKey,MetricPrevData>();
  foreachInstanceUsageEvent(report.getBeginMs() - USAGE_SEARCH_PERIOD,report.getEndMs() + USAGE_SEARCH_PERIOD,new Predicate<ReportingInstanceUsageEvent>(){
    @Override public boolean apply(    final ReportingInstanceUsageEvent event){
      final InstanceMetricDimensionKey key=new InstanceMetricDimensionKey(event.getUuid(),event.getMetric(),event.getDimension());
      final long eventMs=event.getTimestampMs();
      if (event.getValue() == null)       return true;
      final InstanceUsageArtEntity usageEntity=usageEntities.get(event.getUuid());
      if (usageEntity == null)       return true;
      if (!prevDataMap.containsKey(key)) {
        if (instanceStartTimes.containsKey(event.getUuid())) {
          Double fractionalVal=fractionalUsage(report.getBeginMs(),report.getEndMs(),instanceStartTimes.get(event.getUuid()),eventMs,event.getValue());
          addMetricValueToUsageEntity(usageEntity,event.getMetric(),event.getDimension(),fractionalVal);
          log.debug(String.format("String_Node_Str",instanceStartTimes.get(event.getUuid()),eventMs,report.getBeginMs(),report.getEndMs(),event.getUuid(),event.getMetric(),event.getDimension(),event.getValue(),fractionalVal));
        }
        prevDataMap.put(key,new MetricPrevData(eventMs,eventMs,event.getValue(),event.getSequenceNum()));
      }
 else {
        final MetricPrevData prevData=prevDataMap.get(key);
        usageEntity.setDurationMs(Math.max(usageEntity.getDurationMs(),overlap(report.getBeginMs(),report.getEndMs(),prevData.firstMs,eventMs)));
        if (event.getSequenceNum() < prevData.lastSeq) {
          Double fractionalVal=fractionalUsage(report.getBeginMs(),report.getEndMs(),prevData.lastMs,eventMs,event.getValue());
          addMetricValueToUsageEntity(usageEntity,event.getMetric(),event.getDimension(),fractionalVal);
          log.debug(String.format("String_Node_Str",prevData.lastMs,eventMs,report.getBeginMs(),report.getEndMs(),event.getUuid(),event.getMetric(),event.getDimension(),event.getValue(),fractionalVal));
        }
 else {
          Double fractionalVal=fractionalUsage(report.getBeginMs(),report.getEndMs(),prevData.lastMs,eventMs,event.getValue() - prevData.lastVal);
          addMetricValueToUsageEntity(usageEntity,event.getMetric(),event.getDimension(),fractionalVal);
          log.debug(String.format("String_Node_Str",prevData.lastMs,eventMs,report.getBeginMs(),report.getEndMs(),event.getUuid(),event.getMetric(),event.getDimension(),event.getValue(),prevData.lastVal,fractionalVal));
        }
        prevDataMap.put(key,new MetricPrevData(prevData.firstMs,eventMs,event.getValue(),event.getSequenceNum()));
      }
      return true;
    }
  }
);
  for (  final AvailabilityZoneArtEntity zone : report.getZones().values()) {
    final UsageTotalsArtEntity zoneUsage=zone.getUsageTotals();
    for (    final AccountArtEntity account : zone.getAccounts().values()) {
      final UsageTotalsArtEntity accountUsage=account.getUsageTotals();
      for (      final UserArtEntity user : account.getUsers().values()) {
        final UsageTotalsArtEntity userUsage=user.getUsageTotals();
        for (        final InstanceArtEntity instance : user.getInstances().values()) {
          updateUsageTotals(userUsage,instance);
          updateUsageTotals(accountUsage,instance);
          updateUsageTotals(zoneUsage,instance);
        }
      }
    }
  }
  return report;
}

Fixed version (ground truth):
@Override public ReportArtEntity generateReportArt(final ReportArtEntity report){
  log.debug("String_Node_Str");
  final Map<String,ReportingInstanceCreateEvent> createEvents=new HashMap<String,ReportingInstanceCreateEvent>();
  foreachInstanceCreateEvent(report.getEndMs(),new Predicate<ReportingInstanceCreateEvent>(){
    @Override public boolean apply(    final ReportingInstanceCreateEvent createEvent){
      createEvents.put(createEvent.getUuid(),createEvent);
      return true;
    }
  }
);
  final Map<InstanceMetricDimensionKey,MetricPrevData> prevDataMap=new HashMap<InstanceMetricDimensionKey,MetricPrevData>();
  final Map<String,InstanceUsageArtEntity> usageEntities=new HashMap<String,InstanceUsageArtEntity>();
  foreachInstanceUsageEvent(report.getBeginMs() - USAGE_SEARCH_PERIOD,report.getEndMs() + USAGE_SEARCH_PERIOD,new Predicate<ReportingInstanceUsageEvent>(){
    @Override public boolean apply(    final ReportingInstanceUsageEvent event){
      final InstanceMetricDimensionKey key=new InstanceMetricDimensionKey(event.getUuid(),event.getMetric(),event.getDimension());
      final long eventMs=event.getTimestampMs();
      if (event.getValue() == null)       return true;
      if (!usageEntities.containsKey(event.getUuid())) {
        usageEntities.put(event.getUuid(),new InstanceUsageArtEntity());
      }
      final InstanceUsageArtEntity usageEntity=usageEntities.get(event.getUuid());
      final ReportingInstanceCreateEvent createEvent=createEvents.get(event.getUuid());
      if (createEvent == null) {
        log.error("String_Node_Str" + event.getUuid());
        return true;
      }
      if (eventMs >= report.getBeginMs() || eventMs <= report.getEndMs()) {
        addParentNodes(report,createEvent,usageEntity);
      }
      if (!prevDataMap.containsKey(key)) {
        Double fractionalVal=fractionalUsage(report.getBeginMs(),report.getEndMs(),createEvent.getTimestampMs(),eventMs,event.getValue());
        addMetricValueToUsageEntity(usageEntity,event.getMetric(),event.getDimension(),fractionalVal);
        log.debug(String.format("String_Node_Str",createEvent.getTimestampMs(),eventMs,report.getBeginMs(),report.getEndMs(),event.getUuid(),event.getMetric(),event.getDimension(),event.getValue(),fractionalVal));
        prevDataMap.put(key,new MetricPrevData(eventMs,eventMs,event.getValue(),event.getSequenceNum()));
      }
 else {
        final MetricPrevData prevData=prevDataMap.get(key);
        usageEntity.setDurationMs(Math.max(usageEntity.getDurationMs(),overlap(report.getBeginMs(),report.getEndMs(),prevData.firstMs,eventMs)));
        if (event.getSequenceNum() < prevData.lastSeq) {
          Double fractionalVal=fractionalUsage(report.getBeginMs(),report.getEndMs(),prevData.lastMs,eventMs,event.getValue());
          addMetricValueToUsageEntity(usageEntity,event.getMetric(),event.getDimension(),fractionalVal);
          log.debug(String.format("String_Node_Str",prevData.lastMs,eventMs,report.getBeginMs(),report.getEndMs(),event.getUuid(),event.getMetric(),event.getDimension(),event.getValue(),fractionalVal));
        }
 else {
          Double fractionalVal=fractionalUsage(report.getBeginMs(),report.getEndMs(),prevData.lastMs,eventMs,event.getValue() - prevData.lastVal);
          addMetricValueToUsageEntity(usageEntity,event.getMetric(),event.getDimension(),fractionalVal);
          log.debug(String.format("String_Node_Str",prevData.lastMs,eventMs,report.getBeginMs(),report.getEndMs(),event.getUuid(),event.getMetric(),event.getDimension(),event.getValue(),prevData.lastVal,fractionalVal));
        }
        prevDataMap.put(key,new MetricPrevData(prevData.firstMs,eventMs,event.getValue(),event.getSequenceNum()));
      }
      return true;
    }
  }
);
  for (  final AvailabilityZoneArtEntity zone : report.getZones().values()) {
    final UsageTotalsArtEntity zoneUsage=zone.getUsageTotals();
    for (    final AccountArtEntity account : zone.getAccounts().values()) {
      final UsageTotalsArtEntity accountUsage=account.getUsageTotals();
      for (      final UserArtEntity user : account.getUsers().values()) {
        final UsageTotalsArtEntity userUsage=user.getUsageTotals();
        for (        final InstanceArtEntity instance : user.getInstances().values()) {
          updateUsageTotals(userUsage,instance);
          updateUsageTotals(accountUsage,instance);
          updateUsageTotals(zoneUsage,instance);
        }
      }
    }
  }
  return report;
}