Program: 18529
Project: 18529
Buggy source:
/** 
 * {@inheritDoc}
 */
@Override public List<MetricGraphData> getMetricValue(CriteriaInfo criteriaInfo,long beginTime,long duration,int aggregationPeriod,String autoDelay){
  List<MetricGraphData> result=new ArrayList<MetricGraphData>();
  Map<Long,MetricGraphData> metricGraphDataByTime=new TreeMap<Long,MetricGraphData>();
  String encodedMetricName=criteriaInfo.getMetricName();
  String metricName=decodeMetricName(encodedMetricName);
  long endTime=beginTime + TimeUnit.SECONDS.toMillis(duration);
  boolean serverSide=MonitoringSystem.COLLECTION_LOCATION_SERVER.equals(criteriaInfo.getRoleType());
  boolean totalizeResultsPerService=false;
  Map<String,List<String>> filters=new HashMap<String,List<String>>();
  if (criteriaInfo.getServiceName() != null) {
    filters.put("String_Node_Str",Arrays.asList(criteriaInfo.getServiceName().trim()));
  }
  if (criteriaInfo.getOperationName() != null) {
    filters.put("String_Node_Str",Arrays.asList(criteriaInfo.getOperationName().trim()));
  }
  if (criteriaInfo.getConsumerName() != null) {
    filters.put("String_Node_Str",Arrays.asList(criteriaInfo.getConsumerName().trim()));
  }
  Map<String,List<MetricValue<?>>> metricValuesMap;
  List<String> serviceNames=filters.get("String_Node_Str");
  List<String> operationNames=filters.get("String_Node_Str");
  List<String> consumerNames=filters.get("String_Node_Str");
  if (operationNames == null || operationNames.isEmpty()) {
    operationNames=metricsServiceOperationByIpDAO.findMetricOperationNames(serviceNames);
    operationNames=removeServiceNamePrefix(operationNames);
    filters.put("String_Node_Str",operationNames);
    totalizeResultsPerService=true;
  }
  if (consumerNames != null && !consumerNames.isEmpty()) {
    for (    String serviceName : serviceNames) {
      List<String> ipAddressList=ipPerDayAndServiceNameDAO.findByDateAndServiceName(System.currentTimeMillis(),serviceName);
      metricValuesMap=metricValuesDAO.findMetricValuesByConsumer(ipAddressList,metricName,beginTime,endTime,serverSide,aggregationPeriod,serviceName,operationNames,consumerNames);
      for (      String consumerName : consumerNames) {
        List<MetricValue<?>> metricValues=metricValuesMap.get(consumerName);
        for (int i=0; i < duration / aggregationPeriod; ++i) {
          long startTime=beginTime + TimeUnit.SECONDS.toMillis(i * aggregationPeriod);
          long stopTime=startTime + TimeUnit.SECONDS.toMillis(aggregationPeriod);
          double value=0;
          for (          MetricValue<?> metricValue : metricValues) {
            long time=metricValue.getTimeMiliseconds();
            if (startTime <= time && time < stopTime) {
              value+=metricValue.getValueForMetric(encodedMetricName);
            }
          }
          MetricGraphData metricGraphData=new MetricGraphData();
          metricGraphData.setCount(value);
          metricGraphData.setTimeSlot(startTime);
          metricGraphData.setCriteria(null);
          if (totalizeResultsPerService) {
            MetricGraphData alreadyStoredMetricGraph=null;
            if (metricGraphDataByTime.containsKey(startTime)) {
              alreadyStoredMetricGraph=metricGraphDataByTime.get(startTime);
              alreadyStoredMetricGraph.setCount(metricGraphData.getCount() + alreadyStoredMetricGraph.getCount());
            }
 else {
              result.add(metricGraphData);
              metricGraphDataByTime.put(startTime,metricGraphData);
            }
          }
 else {
            result.add(metricGraphData);
          }
        }
      }
    }
  }
 else {
    for (    String serviceName : serviceNames) {
      List<String> ipAddressList=ipPerDayAndServiceNameDAO.findByDateAndServiceName(System.currentTimeMillis(),serviceName);
      metricValuesMap=metricValuesDAO.findMetricValuesByOperation(ipAddressList,metricName,beginTime,endTime,serverSide,aggregationPeriod,filters);
      operationNames=filters.get("String_Node_Str");
      for (      String opName : operationNames) {
        List<MetricValue<?>> metricValues=metricValuesMap.get(opName);
        for (int i=0; i < duration / aggregationPeriod; ++i) {
          long startTime=beginTime + TimeUnit.SECONDS.toMillis(i * aggregationPeriod);
          long stopTime=startTime + TimeUnit.SECONDS.toMillis(aggregationPeriod);
          double value=0;
          for (          MetricValue<?> metricValue : metricValues) {
            long time=metricValue.getTimeMiliseconds();
            if (startTime <= time && time < stopTime) {
              value+=metricValue.getValueForMetric(encodedMetricName);
              break;
            }
          }
          MetricGraphData metricGraphData=new MetricGraphData();
          metricGraphData.setCount(value);
          metricGraphData.setTimeSlot(startTime);
          metricGraphData.setCriteria(null);
          if (totalizeResultsPerService) {
            MetricGraphData alreadyStoredMetricGraph=null;
            if (metricGraphDataByTime.containsKey(startTime)) {
              alreadyStoredMetricGraph=metricGraphDataByTime.get(startTime);
              alreadyStoredMetricGraph.setCount(metricGraphData.getCount() + alreadyStoredMetricGraph.getCount());
            }
 else {
              result.add(metricGraphData);
              metricGraphDataByTime.put(startTime,metricGraphData);
            }
          }
 else {
            result.add(metricGraphData);
          }
        }
      }
    }
  }
  return result;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public List<MetricGraphData> getMetricValue(CriteriaInfo criteriaInfo,long beginTime,long duration,int aggregationPeriod,String autoDelay){
  List<MetricGraphData> result=new ArrayList<MetricGraphData>();
  Map<Long,MetricGraphData> metricGraphDataByTime=new TreeMap<Long,MetricGraphData>();
  String encodedMetricName=criteriaInfo.getMetricName();
  String metricName=decodeMetricName(encodedMetricName);
  long endTime=beginTime + TimeUnit.SECONDS.toMillis(duration);
  boolean serverSide=MonitoringSystem.COLLECTION_LOCATION_SERVER.equals(criteriaInfo.getRoleType());
  boolean totalizeResultsPerService=false;
  Map<String,List<String>> filters=new HashMap<String,List<String>>();
  if (criteriaInfo.getServiceName() != null) {
    filters.put("String_Node_Str",Arrays.asList(criteriaInfo.getServiceName().trim()));
  }
  if (criteriaInfo.getOperationName() != null) {
    filters.put("String_Node_Str",Arrays.asList(criteriaInfo.getOperationName().trim()));
  }
  if (criteriaInfo.getConsumerName() != null) {
    filters.put("String_Node_Str",Arrays.asList(criteriaInfo.getConsumerName().trim()));
  }
  Map<String,List<MetricValue<?>>> metricValuesMap;
  List<String> serviceNames=filters.get("String_Node_Str");
  List<String> operationNames=filters.get("String_Node_Str");
  List<String> consumerNames=filters.get("String_Node_Str");
  if (operationNames == null || operationNames.isEmpty()) {
    operationNames=metricsServiceOperationByIpDAO.findMetricOperationNames(serviceNames);
    operationNames=removeServiceNamePrefix(operationNames);
    filters.put("String_Node_Str",operationNames);
    totalizeResultsPerService=true;
  }
  if (consumerNames != null && !consumerNames.isEmpty()) {
    for (    String serviceName : serviceNames) {
      List<String> ipAddressList=ipPerDayAndServiceNameDAO.findByDateAndServiceName(beginTime,serviceName);
      ipAddressList=ListUtils.sum(ipAddressList,ipPerDayAndServiceNameDAO.findByDateAndServiceName(endTime,serviceName));
      metricValuesMap=metricValuesDAO.findMetricValuesByConsumer(ipAddressList,metricName,beginTime,endTime,serverSide,aggregationPeriod,serviceName,operationNames,consumerNames);
      for (      String consumerName : consumerNames) {
        List<MetricValue<?>> metricValues=metricValuesMap.get(consumerName);
        for (int i=0; i < duration / aggregationPeriod; ++i) {
          long startTime=beginTime + TimeUnit.SECONDS.toMillis(i * aggregationPeriod);
          long stopTime=startTime + TimeUnit.SECONDS.toMillis(aggregationPeriod);
          double value=0;
          if (metricValues != null) {
            for (            MetricValue<?> metricValue : metricValues) {
              long time=metricValue.getTimeMiliseconds();
              if (startTime <= time && time < stopTime) {
                value+=metricValue.getValueForMetric(encodedMetricName);
              }
            }
          }
          MetricGraphData metricGraphData=new MetricGraphData();
          metricGraphData.setCount(value);
          metricGraphData.setTimeSlot(startTime);
          metricGraphData.setCriteria(null);
          if (totalizeResultsPerService) {
            MetricGraphData alreadyStoredMetricGraph=null;
            if (metricGraphDataByTime.containsKey(startTime)) {
              alreadyStoredMetricGraph=metricGraphDataByTime.get(startTime);
              alreadyStoredMetricGraph.setCount(metricGraphData.getCount() + alreadyStoredMetricGraph.getCount());
            }
 else {
              result.add(metricGraphData);
              metricGraphDataByTime.put(startTime,metricGraphData);
            }
          }
 else {
            result.add(metricGraphData);
          }
        }
      }
    }
  }
 else {
    for (    String serviceName : serviceNames) {
      List<String> ipAddressList=ipPerDayAndServiceNameDAO.findByDateAndServiceName(beginTime,serviceName);
      ipAddressList=ListUtils.sum(ipAddressList,ipPerDayAndServiceNameDAO.findByDateAndServiceName(endTime,serviceName));
      metricValuesMap=metricValuesDAO.findMetricValuesByOperation(ipAddressList,metricName,beginTime,endTime,serverSide,aggregationPeriod,filters);
      operationNames=filters.get("String_Node_Str");
      for (      String opName : operationNames) {
        List<MetricValue<?>> metricValues=metricValuesMap.get(opName);
        for (int i=0; i < duration / aggregationPeriod; ++i) {
          long startTime=beginTime + TimeUnit.SECONDS.toMillis(i * aggregationPeriod);
          long stopTime=startTime + TimeUnit.SECONDS.toMillis(aggregationPeriod);
          double value=0;
          if (metricValues != null) {
            for (            MetricValue<?> metricValue : metricValues) {
              long time=metricValue.getTimeMiliseconds();
              if (startTime <= time && time < stopTime) {
                value+=metricValue.getValueForMetric(encodedMetricName);
                break;
              }
            }
          }
          MetricGraphData metricGraphData=new MetricGraphData();
          metricGraphData.setCount(value);
          metricGraphData.setTimeSlot(startTime);
          metricGraphData.setCriteria(null);
          if (totalizeResultsPerService) {
            MetricGraphData alreadyStoredMetricGraph=null;
            if (metricGraphDataByTime.containsKey(startTime)) {
              alreadyStoredMetricGraph=metricGraphDataByTime.get(startTime);
              alreadyStoredMetricGraph.setCount(metricGraphData.getCount() + alreadyStoredMetricGraph.getCount());
            }
 else {
              result.add(metricGraphData);
              metricGraphDataByTime.put(startTime,metricGraphData);
            }
          }
 else {
            result.add(metricGraphData);
          }
        }
      }
    }
  }
  return result;
}