Program: 105741
Project: 105741
Buggy source:
protected HashMap<String,VmStatsEntry> getVmStats(Connection conn,GetVmStatsCommand cmd,List<String> vmUUIDs,String hostGuid){
  HashMap<String,VmStatsEntry> vmResponseMap=new HashMap<String,VmStatsEntry>();
  for (  String vmUUID : vmUUIDs) {
    vmResponseMap.put(vmUUID,new VmStatsEntry(0,0,0,0,"String_Node_Str"));
  }
  Object[] rrdData=getRRDData(conn,2);
  if (rrdData == null) {
    return null;
  }
  Integer numRows=(Integer)rrdData[0];
  Integer numColumns=(Integer)rrdData[1];
  Node legend=(Node)rrdData[2];
  Node dataNode=(Node)rrdData[3];
  NodeList legendChildren=legend.getChildNodes();
  for (int col=0; col < numColumns; col++) {
    if (legendChildren == null || legendChildren.item(col) == null) {
      continue;
    }
    String columnMetadata=getXMLNodeValue(legendChildren.item(col));
    if (columnMetadata == null) {
      continue;
    }
    String[] columnMetadataList=columnMetadata.split("String_Node_Str");
    if (columnMetadataList.length != 4) {
      continue;
    }
    String type=columnMetadataList[1];
    String uuid=columnMetadataList[2];
    String param=columnMetadataList[3];
    if (type.equals("String_Node_Str") && vmResponseMap.keySet().contains(uuid)) {
      VmStatsEntry vmStatsAnswer=vmResponseMap.get(uuid);
      vmStatsAnswer.setEntityType("String_Node_Str");
      if (param.contains("String_Node_Str")) {
        vmStatsAnswer.setNumCPUs(vmStatsAnswer.getNumCPUs() + 1);
        vmStatsAnswer.setCPUUtilization(((vmStatsAnswer.getCPUUtilization() + getDataAverage(dataNode,col,numRows))));
      }
 else       if (param.matches("String_Node_Str")) {
        vmStatsAnswer.setNetworkReadKBs(vmStatsAnswer.getNetworkReadKBs() + (getDataAverage(dataNode,col,numRows) / (8 * 2)));
      }
 else       if (param.matches("String_Node_Str")) {
        vmStatsAnswer.setNetworkWriteKBs(vmStatsAnswer.getNetworkWriteKBs() + (getDataAverage(dataNode,col,numRows) / (8 * 2)));
      }
    }
  }
  for (  String vmUUID : vmResponseMap.keySet()) {
    VmStatsEntry vmStatsAnswer=vmResponseMap.get(vmUUID);
    if (vmStatsAnswer.getNumCPUs() != 0) {
      vmStatsAnswer.setCPUUtilization(vmStatsAnswer.getCPUUtilization() / vmStatsAnswer.getNumCPUs());
    }
    vmStatsAnswer.setCPUUtilization(vmStatsAnswer.getCPUUtilization() * 100);
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + vmStatsAnswer.getCPUUtilization());
    }
  }
  try {
    for (    String vmUUID : vmUUIDs) {
      VM vm=VM.getByUuid(conn,vmUUID);
      VmStatsEntry stats=vmResponseMap.get(vmUUID);
      double diskReadKBs=0;
      double diskWriteKBs=0;
      for (      VBD vbd : vm.getVBDs(conn)) {
        VBDMetrics vbdmetrics=vbd.getMetrics(conn);
        if (!isRefNull(vbdmetrics)) {
          try {
            diskReadKBs+=vbdmetrics.getIoReadKbs(conn);
            diskWriteKBs+=vbdmetrics.getIoWriteKbs(conn);
          }
 catch (          Types.HandleInvalid e) {
            s_logger.debug("String_Node_Str");
          }
        }
      }
      if (stats == null) {
        stats=new VmStatsEntry();
      }
      stats.setDiskReadKBs(diskReadKBs);
      stats.setDiskWriteKBs(diskWriteKBs);
      vmResponseMap.put(vmUUID,stats);
    }
  }
 catch (  Exception e) {
    s_logger.warn("String_Node_Str",e);
    return null;
  }
  return vmResponseMap;
}

Fixed version (ground truth):
protected HashMap<String,VmStatsEntry> getVmStats(Connection conn,GetVmStatsCommand cmd,List<String> vmUUIDs,String hostGuid){
  HashMap<String,VmStatsEntry> vmResponseMap=new HashMap<String,VmStatsEntry>();
  for (  String vmUUID : vmUUIDs) {
    vmResponseMap.put(vmUUID,new VmStatsEntry(0,0,0,0,"String_Node_Str"));
  }
  Object[] rrdData=getRRDData(conn,2);
  if (rrdData == null) {
    return null;
  }
  Integer numRows=(Integer)rrdData[0];
  Integer numColumns=(Integer)rrdData[1];
  Node legend=(Node)rrdData[2];
  Node dataNode=(Node)rrdData[3];
  NodeList legendChildren=legend.getChildNodes();
  for (int col=0; col < numColumns; col++) {
    if (legendChildren == null || legendChildren.item(col) == null) {
      continue;
    }
    String columnMetadata=getXMLNodeValue(legendChildren.item(col));
    if (columnMetadata == null) {
      continue;
    }
    String[] columnMetadataList=columnMetadata.split("String_Node_Str");
    if (columnMetadataList.length != 4) {
      continue;
    }
    String type=columnMetadataList[1];
    String uuid=columnMetadataList[2];
    String param=columnMetadataList[3];
    if (type.equals("String_Node_Str") && vmResponseMap.keySet().contains(uuid)) {
      VmStatsEntry vmStatsAnswer=vmResponseMap.get(uuid);
      vmStatsAnswer.setEntityType("String_Node_Str");
      if (param.contains("String_Node_Str")) {
        vmStatsAnswer.setNumCPUs(vmStatsAnswer.getNumCPUs() + 1);
        vmStatsAnswer.setCPUUtilization(((vmStatsAnswer.getCPUUtilization() + getDataAverage(dataNode,col,numRows))));
      }
 else       if (param.matches("String_Node_Str")) {
        vmStatsAnswer.setNetworkReadKBs(vmStatsAnswer.getNetworkReadKBs() + (getDataAverage(dataNode,col,numRows) / (8 * 2)));
      }
 else       if (param.matches("String_Node_Str")) {
        vmStatsAnswer.setNetworkWriteKBs(vmStatsAnswer.getNetworkWriteKBs() + (getDataAverage(dataNode,col,numRows) / (8 * 2)));
      }
    }
  }
  for (  Map.Entry<String,VmStatsEntry> entry : vmResponseMap.entrySet()) {
    VmStatsEntry vmStatsAnswer=entry.getValue();
    if (vmStatsAnswer.getNumCPUs() != 0) {
      vmStatsAnswer.setCPUUtilization(vmStatsAnswer.getCPUUtilization() / vmStatsAnswer.getNumCPUs());
    }
    vmStatsAnswer.setCPUUtilization(vmStatsAnswer.getCPUUtilization() * 100);
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + vmStatsAnswer.getCPUUtilization());
    }
  }
  try {
    for (    String vmUUID : vmUUIDs) {
      VM vm=VM.getByUuid(conn,vmUUID);
      VmStatsEntry stats=vmResponseMap.get(vmUUID);
      double diskReadKBs=0;
      double diskWriteKBs=0;
      for (      VBD vbd : vm.getVBDs(conn)) {
        VBDMetrics vbdmetrics=vbd.getMetrics(conn);
        if (!isRefNull(vbdmetrics)) {
          try {
            diskReadKBs+=vbdmetrics.getIoReadKbs(conn);
            diskWriteKBs+=vbdmetrics.getIoWriteKbs(conn);
          }
 catch (          Types.HandleInvalid e) {
            s_logger.debug("String_Node_Str");
          }
        }
      }
      if (stats == null) {
        stats=new VmStatsEntry();
      }
      stats.setDiskReadKBs(diskReadKBs);
      stats.setDiskWriteKBs(diskWriteKBs);
      vmResponseMap.put(vmUUID,stats);
    }
  }
 catch (  Exception e) {
    s_logger.warn("String_Node_Str",e);
    return null;
  }
  return vmResponseMap;
}