Program: 14440
Project: 14440
Buggy source:
public ReportArtEntity generateReportArt(ReportArtEntity report){
  log.debug("String_Node_Str");
  EntityWrapper wrapper=EntityWrapper.get(ReportingS3ObjectCreateEvent.class);
  Iterator iter=wrapper.scanWithNativeQuery("String_Node_Str");
  Map<String,BucketUsageArtEntity> bucketUsageEntities=new HashMap<String,BucketUsageArtEntity>();
  Map<S3ObjectKey,S3ObjectData> objectData=new HashMap<S3ObjectKey,S3ObjectData>();
  DurationCalculator<S3ObjectKey> objectDurationCalculator=new DurationCalculator<S3ObjectKey>(report.getBeginMs(),report.getEndMs());
  while (iter.hasNext()) {
    ReportingS3ObjectCreateEvent createEvent=(ReportingS3ObjectCreateEvent)iter.next();
    ReportingUser reportingUser=ReportingUserDao.getInstance().getReportingUser(createEvent.getUserId());
    if (reportingUser == null) {
      log.error("String_Node_Str" + createEvent.getUserId());
    }
    ReportingAccount reportingAccount=ReportingAccountDao.getInstance().getReportingAccount(reportingUser.getAccountId());
    if (reportingAccount == null) {
      log.error("String_Node_Str" + reportingUser.getAccountId());
    }
    if (!report.getAccounts().containsKey(reportingAccount.getName())) {
      report.getAccounts().put(reportingAccount.getName(),new AccountArtEntity());
    }
    AccountArtEntity account=report.getAccounts().get(reportingAccount.getName());
    if (!account.getUsers().containsKey(reportingUser.getName())) {
      account.getUsers().put(reportingUser.getName(),new UserArtEntity());
    }
    UserArtEntity user=account.getUsers().get(reportingUser.getName());
    if (!user.getBucketUsage().containsKey(createEvent.getS3BucketName())) {
      user.getBucketUsage().put(createEvent.getS3BucketName(),new BucketUsageArtEntity());
    }
    BucketUsageArtEntity bucketUsage=user.getBucketUsage().get(createEvent.getS3BucketName());
    bucketUsageEntities.put(createEvent.getS3BucketName(),bucketUsage);
    S3ObjectKey objectKey=new S3ObjectKey(createEvent.getS3BucketName(),createEvent.getS3ObjectKey(),createEvent.getObjectVersion());
    objectDurationCalculator.addStart(objectKey,createEvent.getTimestampMs());
    objectData.put(objectKey,new S3ObjectData(createEvent.getSizeGB()));
  }
  iter=wrapper.scanWithNativeQuery("String_Node_Str");
  while (iter.hasNext()) {
    ReportingS3ObjectDeleteEvent deleteEvent=(ReportingS3ObjectDeleteEvent)iter.next();
    if (deleteEvent.getTimestampMs() < report.getEndMs()) {
      S3ObjectKey key=new S3ObjectKey(deleteEvent.getS3BucketName(),deleteEvent.getS3ObjectKey(),deleteEvent.getObjectVersion());
      objectDurationCalculator.addEnd(key,deleteEvent.getTimestampMs());
    }
  }
  Map<S3ObjectKey,Long> durationMap=objectDurationCalculator.getDurationMap();
  for (  S3ObjectKey key : durationMap.keySet()) {
    if (objectData.containsKey(key)) {
      objectData.get(key).durationMs=durationMap.get(key);
    }
  }
  for (  S3ObjectKey objKey : objectData.keySet()) {
    S3ObjectData data=objectData.get(objKey);
    if (bucketUsageEntities.containsKey(objKey.bucketName)) {
      BucketUsageArtEntity usage=bucketUsageEntities.get(objKey.bucketName);
      usage.setObjectsNum(usage.getObjectsNum() + 1);
      long gBSecs=(data.durationMs / 1000) * data.sizeGB;
      usage.setGBSecs(gBSecs);
      usage.setSizeGB(usage.getSizeGB() + data.sizeGB);
    }
 else {
      log.error("String_Node_Str" + objKey.bucketName);
    }
  }
  for (  String accountName : report.getAccounts().keySet()) {
    AccountArtEntity account=report.getAccounts().get(accountName);
    for (    String userName : account.getUsers().keySet()) {
      UserArtEntity user=account.getUsers().get(userName);
      for (      String bucketName : user.getBucketUsage().keySet()) {
        BucketUsageArtEntity usage=user.getBucketUsage().get(bucketName);
        updateUsageTotals(user.getUsageTotals().getBucketTotals(),usage);
        updateUsageTotals(account.getUsageTotals().getBucketTotals(),usage);
      }
    }
  }
  return report;
}

Fixed version (ground truth):
public ReportArtEntity generateReportArt(final ReportArtEntity report){
  log.debug("String_Node_Str");
  final Map<String,BucketUsageArtEntity> bucketUsageEntities=new HashMap<String,BucketUsageArtEntity>();
  final Map<S3ObjectKey,S3ObjectData> objectData=new HashMap<S3ObjectKey,S3ObjectData>();
  final DurationCalculator<S3ObjectKey> objectDurationCalculator=new DurationCalculator<S3ObjectKey>(report.getBeginMs(),report.getEndMs());
  foreachReportingS3ObjectCreateEvent(report.getEndMs(),new Predicate<ReportingS3ObjectCreateEvent>(){
    @Override public boolean apply(    final ReportingS3ObjectCreateEvent createEvent){
      ReportingUser reportingUser=ReportingUserDao.getInstance().getReportingUser(createEvent.getUserId());
      if (reportingUser == null) {
        log.error("String_Node_Str" + createEvent.getUserId());
      }
      ReportingAccount reportingAccount=ReportingAccountDao.getInstance().getReportingAccount(reportingUser.getAccountId());
      if (reportingAccount == null) {
        log.error("String_Node_Str" + reportingUser.getAccountId());
      }
      if (!report.getAccounts().containsKey(reportingAccount.getName())) {
        report.getAccounts().put(reportingAccount.getName(),new AccountArtEntity());
      }
      AccountArtEntity account=report.getAccounts().get(reportingAccount.getName());
      if (!account.getUsers().containsKey(reportingUser.getName())) {
        account.getUsers().put(reportingUser.getName(),new UserArtEntity());
      }
      UserArtEntity user=account.getUsers().get(reportingUser.getName());
      if (!user.getBucketUsage().containsKey(createEvent.getS3BucketName())) {
        user.getBucketUsage().put(createEvent.getS3BucketName(),new BucketUsageArtEntity());
      }
      BucketUsageArtEntity bucketUsage=user.getBucketUsage().get(createEvent.getS3BucketName());
      bucketUsageEntities.put(createEvent.getS3BucketName(),bucketUsage);
      S3ObjectKey objectKey=new S3ObjectKey(createEvent.getS3BucketName(),createEvent.getS3ObjectKey(),createEvent.getObjectVersion());
      objectDurationCalculator.addStart(objectKey,createEvent.getTimestampMs());
      objectData.put(objectKey,new S3ObjectData(createEvent.getSizeGB()));
      return true;
    }
  }
);
  foreachReportingS3ObjectDeleteEvent(report.getEndMs(),new Predicate<ReportingS3ObjectDeleteEvent>(){
    @Override public boolean apply(    final ReportingS3ObjectDeleteEvent deleteEvent){
      if (deleteEvent.getTimestampMs() < report.getEndMs()) {
        S3ObjectKey key=new S3ObjectKey(deleteEvent.getS3BucketName(),deleteEvent.getS3ObjectKey(),deleteEvent.getObjectVersion());
        objectDurationCalculator.addEnd(key,deleteEvent.getTimestampMs());
      }
      return true;
    }
  }
);
  Map<S3ObjectKey,Long> durationMap=objectDurationCalculator.getDurationMap();
  for (  S3ObjectKey key : durationMap.keySet()) {
    if (objectData.containsKey(key)) {
      objectData.get(key).durationMs=durationMap.get(key);
    }
  }
  for (  S3ObjectKey objKey : objectData.keySet()) {
    S3ObjectData data=objectData.get(objKey);
    if (bucketUsageEntities.containsKey(objKey.bucketName)) {
      BucketUsageArtEntity usage=bucketUsageEntities.get(objKey.bucketName);
      usage.setObjectsNum(usage.getObjectsNum() + 1);
      long gBSecs=(data.durationMs / 1000) * data.sizeGB;
      usage.setGBSecs(gBSecs);
      usage.setSizeGB(usage.getSizeGB() + data.sizeGB);
    }
 else {
      log.error("String_Node_Str" + objKey.bucketName);
    }
  }
  for (  String accountName : report.getAccounts().keySet()) {
    AccountArtEntity account=report.getAccounts().get(accountName);
    for (    String userName : account.getUsers().keySet()) {
      UserArtEntity user=account.getUsers().get(userName);
      for (      String bucketName : user.getBucketUsage().keySet()) {
        BucketUsageArtEntity usage=user.getBucketUsage().get(bucketName);
        updateUsageTotals(user.getUsageTotals().getBucketTotals(),usage);
        updateUsageTotals(account.getUsageTotals().getBucketTotals(),usage);
      }
    }
  }
  return report;
}