Program: 18537
Project: 18537
Buggy source:
@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)) {
    }
 else     if (ResourceEntity.OPERATION.value().equals(groupBy)) {
      data1=metricValuesDAO.findMetricValuesByOperation(metricName,firstStartTime,firstStartTime + duration,serverSide,aggregationPeriod,filters);
      data2=metricValuesDAO.findMetricValuesByOperation(metricName,secondStartTime,secondStartTime + duration,serverSide,aggregationPeriod,filters);
      Map<String,Object> map1=transformAggregatedMetricComponentValues(encodedMetricName,data1);
      Map<String,Object> map2=transformAggregatedMetricComponentValues(encodedMetricName,data2);
      List<String> 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)) {
    }
 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);
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
  return result;
}

Fixed version (ground truth):
@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");
      List<String> operationNames=metricsServiceOperationByIpDAO.findMetricOperationNames(serviceNames);
      operationNames=removeServiceNamePrefix(operationNames);
      filters.put("String_Node_Str",operationNames);
      data1=metricValuesDAO.findMetricValuesByOperation(metricName,firstStartTime,firstStartTime + duration,serverSide,aggregationPeriod,filters);
      data2=metricValuesDAO.findMetricValuesByOperation(metricName,secondStartTime,secondStartTime + duration,serverSide,aggregationPeriod,filters);
      Map<String,Object> map1=transformAggregatedMetricComponentValues(encodedMetricName,data1);
      Map<String,Object> map2=transformAggregatedMetricComponentValues(encodedMetricName,data2);
      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.OPERATION.value().equals(groupBy)) {
      List<String> operationNames=filters.get("String_Node_Str");
      if (operationNames == null || operationNames.isEmpty()) {
        List<String> serviceNames=filters.get("String_Node_Str");
        operationNames=metricsServiceOperationByIpDAO.findMetricOperationNames(serviceNames);
        operationNames=removeServiceNamePrefix(operationNames);
        filters.put("String_Node_Str",operationNames);
      }
      data1=metricValuesDAO.findMetricValuesByOperation(metricName,firstStartTime,firstStartTime + duration,serverSide,aggregationPeriod,filters);
      data2=metricValuesDAO.findMetricValuesByOperation(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)) {
    }
 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);
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
  return result;
}