Program: 18544
Project: 18544
Buggy source:
/** 
 * {@inheritDoc}
 */
@Override public List<MetricGroupData> getMetricsData(MetricCriteria metricCriteria,MetricResourceCriteria metricResourceCriteria){
  List<MetricGroupData> result=new ArrayList<MetricGroupData>();
  try {
    String encodedMetricName=metricCriteria.getMetricName();
    String metricName=decodeMetricName(encodedMetricName);
    Map<String,List<String>> filters=new HashMap<String,List<String>>();
    for (    ResourceEntity resourceEntityType : ResourceEntity.values()) {
      List<String> resourceEntityNames=null;
      for (      ResourceEntityRequest resourceEntityRequest : metricResourceCriteria.getResourceRequestEntities()) {
        if (resourceEntityRequest.getResourceEntityType() == resourceEntityType) {
          resourceEntityNames=resourceEntityRequest.getResourceEntityName();
          break;
        }
      }
      if (resourceEntityNames == null) {
        resourceEntityNames=Collections.emptyList();
      }
      if (!resourceEntityNames.isEmpty()) {
        filters.put(resourceEntityType.value(),resourceEntityNames);
      }
    }
    String groupBy=metricResourceCriteria.getResourceEntityResponseType();
    long firstStartTime=metricCriteria.getFirstStartTime();
    long secondStartTime=metricCriteria.getSecondStartTime();
    long duration=TimeUnit.SECONDS.toMillis(metricCriteria.getDuration());
    int aggregationPeriod=metricCriteria.getAggregationPeriod();
    boolean serverSide=!MonitoringSystem.COLLECTION_LOCATION_CLIENT.equals(metricCriteria.getRoleType());
    Map<String,List<MetricValue<?>>> data1=null;
    Map<String,List<MetricValue<?>>> data2=null;
    if (ResourceEntity.SERVICE.value().equals(groupBy)) {
      List<String> serviceNames=filters.get("String_Node_Str");
      for (      String serviceName : serviceNames) {
        List<String> ipAddressList=ipPerDayAndServiceNameDAO.findByDateAndServiceName(System.currentTimeMillis(),serviceName);
        List<String> operationNames=metricsServiceOperationByIpDAO.findMetricOperationNames(serviceNames);
        operationNames=removeServiceNamePrefix(operationNames);
        filters.put("String_Node_Str",operationNames);
        data1=metricValuesDAO.findMetricValuesByOperation(ipAddressList,metricName,firstStartTime,firstStartTime + duration,serverSide,aggregationPeriod,filters);
        data2=metricValuesDAO.findMetricValuesByOperation(ipAddressList,metricName,secondStartTime,secondStartTime + duration,serverSide,aggregationPeriod,filters);
        Map<String,Object> map1=transformAggregatedMetricComponentValues(encodedMetricName,data1);
        Map<String,Object> map2=transformAggregatedMetricComponentValues(encodedMetricName,data2);
        MetricGroupData metricGroupData=new MetricGroupData();
        metricGroupData.setCount1((Double)map1.get(serviceName));
        metricGroupData.setCount2((Double)map2.get(serviceName));
        CriteriaInfo criteriaInfo=new CriteriaInfo();
        criteriaInfo.setServiceName(serviceName);
        metricGroupData.setCriteriaInfo(criteriaInfo);
        result.add(metricGroupData);
      }
    }
 else     if (ResourceEntity.OPERATION.value().equals(groupBy)) {
      List<String> operationNames=filters.get("String_Node_Str");
      List<String> serviceNames=filters.get("String_Node_Str");
      if (operationNames == null || operationNames.isEmpty()) {
        operationNames=metricsServiceOperationByIpDAO.findMetricOperationNames(serviceNames);
        operationNames=removeServiceNamePrefix(operationNames);
        filters.put("String_Node_Str",operationNames);
      }
      for (      String serviceName : serviceNames) {
        List<String> ipAddressList=ipPerDayAndServiceNameDAO.findByDateAndServiceName(System.currentTimeMillis(),serviceName);
        data1=metricValuesDAO.findMetricValuesByOperation(ipAddressList,metricName,firstStartTime,firstStartTime + duration,serverSide,aggregationPeriod,filters);
        data2=metricValuesDAO.findMetricValuesByOperation(ipAddressList,metricName,secondStartTime,secondStartTime + duration,serverSide,aggregationPeriod,filters);
        Map<String,Object> map1=transformAggregatedMetricComponentValues(encodedMetricName,data1);
        Map<String,Object> map2=transformAggregatedMetricComponentValues(encodedMetricName,data2);
        operationNames=filters.get("String_Node_Str");
        for (        String operation : operationNames) {
          MetricGroupData metricGroupData=new MetricGroupData();
          metricGroupData.setCount1((Double)map1.get(operation));
          metricGroupData.setCount2((Double)map2.get(operation));
          CriteriaInfo criteriaInfo=new CriteriaInfo();
          criteriaInfo.setOperationName(operation);
          metricGroupData.setCriteriaInfo(criteriaInfo);
          result.add(metricGroupData);
        }
      }
    }
 else     if (ResourceEntity.CONSUMER.value().equals(groupBy)) {
      List<String> operationNames=filters.get("String_Node_Str");
      List<String> serviceNames=filters.get("String_Node_Str");
      if (operationNames == null || operationNames.isEmpty()) {
        operationNames=metricsServiceOperationByIpDAO.findMetricOperationNames(serviceNames);
        operationNames=removeServiceNamePrefix(operationNames);
      }
      List<String> consumerNames=filters.get("String_Node_Str");
      if (consumerNames == null || consumerNames.isEmpty()) {
        consumerNames=metricsServiceConsumerByIpDAO.findMetricConsumerNames(serviceNames);
        filters.put("String_Node_Str",consumerNames);
      }
      for (      String serviceName : serviceNames) {
        List<String> ipAddressList=ipPerDayAndServiceNameDAO.findByDateAndServiceName(System.currentTimeMillis(),serviceName);
        data1=metricValuesDAO.findMetricValuesByConsumer(ipAddressList,metricName,firstStartTime,firstStartTime + duration,serverSide,aggregationPeriod,serviceName,operationNames,consumerNames);
        data2=metricValuesDAO.findMetricValuesByConsumer(ipAddressList,metricName,secondStartTime,secondStartTime + duration,serverSide,aggregationPeriod,serviceName,operationNames,consumerNames);
        Map<String,Object> map1=transformAggregatedMetricComponentValues(encodedMetricName,data1);
        Map<String,Object> map2=transformAggregatedMetricComponentValues(encodedMetricName,data2);
        for (        String consumerName : consumerNames) {
          MetricGroupData metricGroupData=new MetricGroupData();
          metricGroupData.setCount1((Double)map1.get(consumerName));
          metricGroupData.setCount2((Double)map2.get(consumerName));
          CriteriaInfo criteriaInfo=new CriteriaInfo();
          criteriaInfo.setConsumerName(consumerName);
          metricGroupData.setCriteriaInfo(criteriaInfo);
          result.add(metricGroupData);
        }
      }
    }
 else     if ("String_Node_Str".equals(groupBy)) {
    }
 else {
      throw new UnsupportedOperationException();
    }
    final boolean sortAsc=metricCriteria.getSortOrder() == SortOrderType.ASCENDING;
    Collections.sort(result,new Comparator<MetricGroupData>(){
      @Override public int compare(      MetricGroupData mgd1,      MetricGroupData mgd2){
        double v1=Math.max(mgd1.getCount1(),mgd1.getCount2());
        double v2=Math.max(mgd2.getCount1(),mgd2.getCount2());
        if (v1 == v2) {
          v1=mgd1.getCount1() + mgd1.getCount2();
          v2=mgd2.getCount1() + mgd2.getCount2();
        }
        if (v1 == v2) {
          v1=mgd1.getCount2();
          v2=mgd2.getCount2();
        }
        int result=v1 > v2 ? 1 : v1 < v2 ? -1 : 0;
        return sortAsc ? result : -result;
      }
    }
);
    int rows=metricCriteria.getNumRows() == null ? 0 : Integer.parseInt(metricCriteria.getNumRows());
    trimResultList(result,rows);
    removeZeroRowsFromList(result);
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
  return result;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public List<MetricGroupData> getMetricsData(MetricCriteria metricCriteria,MetricResourceCriteria metricResourceCriteria){
  List<MetricGroupData> result=new ArrayList<MetricGroupData>();
  try {
    String encodedMetricName=metricCriteria.getMetricName();
    String metricName=decodeMetricName(encodedMetricName);
    Map<String,List<String>> filters=new HashMap<String,List<String>>();
    for (    ResourceEntity resourceEntityType : ResourceEntity.values()) {
      List<String> resourceEntityNames=null;
      for (      ResourceEntityRequest resourceEntityRequest : metricResourceCriteria.getResourceRequestEntities()) {
        if (resourceEntityRequest.getResourceEntityType() == resourceEntityType) {
          resourceEntityNames=resourceEntityRequest.getResourceEntityName();
          break;
        }
      }
      if (resourceEntityNames == null) {
        resourceEntityNames=Collections.emptyList();
      }
      if (!resourceEntityNames.isEmpty()) {
        filters.put(resourceEntityType.value(),resourceEntityNames);
      }
    }
    String groupBy=metricResourceCriteria.getResourceEntityResponseType();
    long firstStartTime=metricCriteria.getFirstStartTime();
    long secondStartTime=metricCriteria.getSecondStartTime();
    long duration=TimeUnit.SECONDS.toMillis(metricCriteria.getDuration());
    int aggregationPeriod=metricCriteria.getAggregationPeriod();
    boolean serverSide=!MonitoringSystem.COLLECTION_LOCATION_CLIENT.equals(metricCriteria.getRoleType());
    Map<String,List<MetricValue<?>>> data1=null;
    Map<String,List<MetricValue<?>>> data2=null;
    if (ResourceEntity.SERVICE.value().equals(groupBy)) {
      List<String> serviceNames=filters.get("String_Node_Str");
      for (      String serviceName : serviceNames) {
        List<String> ipAddressList=ipPerDayAndServiceNameDAO.findByDateAndServiceName(System.currentTimeMillis(),serviceName);
        List<String> operationNames=metricsServiceOperationByIpDAO.findMetricOperationNames(serviceNames);
        operationNames=removeServiceNamePrefix(operationNames);
        filters.put("String_Node_Str",operationNames);
        data1=metricValuesDAO.findMetricValuesByOperation(ipAddressList,metricName,firstStartTime,firstStartTime + duration,serverSide,aggregationPeriod,filters);
        data2=metricValuesDAO.findMetricValuesByOperation(ipAddressList,metricName,secondStartTime,secondStartTime + duration,serverSide,aggregationPeriod,filters);
        Map<String,Object> map1=transformAggregatedMetricComponentValues(encodedMetricName,data1);
        Map<String,Object> map2=transformAggregatedMetricComponentValues(encodedMetricName,data2);
        MetricGroupData metricGroupData=new MetricGroupData();
        metricGroupData.setCount1((Double)map1.get(serviceName));
        metricGroupData.setCount2((Double)map2.get(serviceName));
        CriteriaInfo criteriaInfo=new CriteriaInfo();
        criteriaInfo.setServiceName(serviceName);
        metricGroupData.setCriteriaInfo(criteriaInfo);
        result.add(metricGroupData);
      }
    }
 else     if (ResourceEntity.OPERATION.value().equals(groupBy)) {
      List<String> operationNames=filters.get("String_Node_Str");
      List<String> serviceNames=filters.get("String_Node_Str");
      if (operationNames == null || operationNames.isEmpty()) {
        operationNames=metricsServiceOperationByIpDAO.findMetricOperationNames(serviceNames);
        operationNames=removeServiceNamePrefix(operationNames);
        filters.put("String_Node_Str",operationNames);
      }
      for (      String serviceName : serviceNames) {
        List<String> ipAddressList=ipPerDayAndServiceNameDAO.findByDateAndServiceName(System.currentTimeMillis(),serviceName);
        data1=metricValuesDAO.findMetricValuesByOperation(ipAddressList,metricName,firstStartTime,firstStartTime + duration,serverSide,aggregationPeriod,filters);
        data2=metricValuesDAO.findMetricValuesByOperation(ipAddressList,metricName,secondStartTime,secondStartTime + duration,serverSide,aggregationPeriod,filters);
        Map<String,Object> map1=transformAggregatedMetricComponentValues(encodedMetricName,data1);
        Map<String,Object> map2=transformAggregatedMetricComponentValues(encodedMetricName,data2);
        operationNames=filters.get("String_Node_Str");
        for (        String operation : operationNames) {
          MetricGroupData metricGroupData=new MetricGroupData();
          metricGroupData.setCount1((Double)map1.get(operation));
          metricGroupData.setCount2((Double)map2.get(operation));
          CriteriaInfo criteriaInfo=new CriteriaInfo();
          criteriaInfo.setOperationName(operation);
          metricGroupData.setCriteriaInfo(criteriaInfo);
          result.add(metricGroupData);
        }
      }
    }
 else     if (ResourceEntity.CONSUMER.value().equals(groupBy)) {
      List<String> operationNames=filters.get("String_Node_Str");
      List<String> serviceNames=filters.get("String_Node_Str");
      if (operationNames == null || operationNames.isEmpty()) {
        operationNames=metricsServiceOperationByIpDAO.findMetricOperationNames(serviceNames);
        operationNames=removeServiceNamePrefix(operationNames);
      }
      List<String> consumerNames=filters.get("String_Node_Str");
      if (consumerNames == null || consumerNames.isEmpty()) {
        consumerNames=metricsServiceConsumerByIpDAO.findMetricConsumerNames(serviceNames);
        filters.put("String_Node_Str",consumerNames);
      }
      for (      String serviceName : serviceNames) {
        List<String> ipAddressList=ipPerDayAndServiceNameDAO.findByDateAndServiceName(System.currentTimeMillis(),serviceName);
        data1=metricValuesDAO.findMetricValuesByConsumer(ipAddressList,metricName,firstStartTime,firstStartTime + duration,serverSide,aggregationPeriod,serviceName,operationNames,consumerNames);
        data2=metricValuesDAO.findMetricValuesByConsumer(ipAddressList,metricName,secondStartTime,secondStartTime + duration,serverSide,aggregationPeriod,serviceName,operationNames,consumerNames);
        Map<String,Object> map1=transformAggregatedMetricComponentValues(encodedMetricName,data1);
        Map<String,Object> map2=transformAggregatedMetricComponentValues(encodedMetricName,data2);
        for (        String consumerName : consumerNames) {
          MetricGroupData metricGroupData=new MetricGroupData();
          metricGroupData.setCount1((Double)map1.get(consumerName));
          metricGroupData.setCount2((Double)map2.get(consumerName));
          CriteriaInfo criteriaInfo=new CriteriaInfo();
          criteriaInfo.setConsumerName(consumerName);
          metricGroupData.setCriteriaInfo(criteriaInfo);
          result.add(metricGroupData);
        }
      }
    }
 else     if ("String_Node_Str".equals(groupBy)) {
      metricName="String_Node_Str";
      List<String> operationNames=filters.get("String_Node_Str");
      List<String> serviceNames=filters.get("String_Node_Str");
      if (operationNames == null || operationNames.isEmpty()) {
        operationNames=metricsServiceOperationByIpDAO.findMetricOperationNames(serviceNames);
        operationNames=removeServiceNamePrefix(operationNames);
        filters.put("String_Node_Str",operationNames);
      }
      List<String> consumerNames=filters.get("String_Node_Str");
      if (consumerNames == null || consumerNames.isEmpty()) {
        consumerNames=metricsServiceConsumerByIpDAO.findMetricConsumerNames(serviceNames);
        filters.put("String_Node_Str",consumerNames);
      }
      for (      String serviceName : serviceNames) {
        List<String> ipAddressList=ipPerDayAndServiceNameDAO.findByDateAndServiceName(System.currentTimeMillis(),serviceName);
        data1=metricValuesDAO.findMetricErrorValuesByOperation(ipAddressList,firstStartTime,firstStartTime + duration,serverSide,aggregationPeriod,filters);
        data2=metricValuesDAO.findMetricErrorValuesByOperation(ipAddressList,secondStartTime,secondStartTime + duration,serverSide,aggregationPeriod,filters);
        Map<String,Object> map1=transformAggregatedMetricComponentValues(encodedMetricName,data1);
        Map<String,Object> map2=transformAggregatedMetricComponentValues(encodedMetricName,data2);
        operationNames=filters.get("String_Node_Str");
        for (        String errorMetricName : metricValuesDAO.getErrorMetricNameList()) {
          MetricGroupData metricGroupData=new MetricGroupData();
          metricGroupData.setCount1((Double)map1.get(errorMetricName));
          metricGroupData.setCount2((Double)map2.get(errorMetricName));
          CriteriaInfo criteriaInfo=new CriteriaInfo();
          criteriaInfo.setMetricName(errorMetricName);
          criteriaInfo.setServiceName(serviceName);
          metricGroupData.setCriteriaInfo(criteriaInfo);
          result.add(metricGroupData);
        }
      }
    }
 else {
      throw new UnsupportedOperationException();
    }
    final boolean sortAsc=metricCriteria.getSortOrder() == SortOrderType.ASCENDING;
    Collections.sort(result,new Comparator<MetricGroupData>(){
      @Override public int compare(      MetricGroupData mgd1,      MetricGroupData mgd2){
        double v1=Math.max(mgd1.getCount1(),mgd1.getCount2());
        double v2=Math.max(mgd2.getCount1(),mgd2.getCount2());
        if (v1 == v2) {
          v1=mgd1.getCount1() + mgd1.getCount2();
          v2=mgd2.getCount1() + mgd2.getCount2();
        }
        if (v1 == v2) {
          v1=mgd1.getCount2();
          v2=mgd2.getCount2();
        }
        int result=v1 > v2 ? 1 : v1 < v2 ? -1 : 0;
        return sortAsc ? result : -result;
      }
    }
);
    int rows=metricCriteria.getNumRows() == null ? 0 : Integer.parseInt(metricCriteria.getNumRows());
    trimResultList(result,rows);
    removeZeroRowsFromList(result);
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
  return result;
}