Program: 48349
Project: 48349
Buggy source:
@ClusterManagerPointcut public Long addCluster(String clusterName,NodeGroupCreate[] nodeGroupsAdd) throws Exception {
  Long taskId=null;
  List<BaseNode> vNodes=new ArrayList<BaseNode>();
  String rpNames=null;
  ClusterCreate clusterSpec=clusterConfigMgr.getClusterConfig(clusterName);
  List<NodeEntity> nodes=clusterEntityMgr.findAllNodes(clusterName);
  for (  NodeEntity node : nodes) {
    rpNames=node.getVcRp().getVcResourcePool();
    if (null != rpNames)     break;
  }
  clusterSpec.setNodeGroups(nodeGroupsAdd);
  for (  NodeGroupCreate ng : nodeGroupsAdd) {
    BaseNode node=new BaseNode();
    NodeGroupEntity group=clusterEntityMgr.findByName(clusterName,ng.getName());
    ClusterEntity clusterEntity=clusterEntityMgr.findByName(clusterName);
    if (clusterEntity == null) {
      throw ClusterConfigException.CLUSTER_CONFIG_NOT_FOUND(clusterName);
    }
    if (0 == ng.getInstanceNum()) {
      throw ClusterManagerException.NODE_GROUP_CANNOT_BE_ZERO(ng.getName());
    }
    if (group == null) {
      NodeGroupEntity addNodeGroupEntity=new NodeGroupEntity();
      addNodeGroupEntity.setName(ng.getName());
      addNodeGroupEntity.setRoles((new Gson()).toJson(ng.getRoles()));
      addNodeGroupEntity.setNodeType(ng.getInstanceType());
      addNodeGroupEntity.setDefineInstanceNum(ng.getInstanceNum());
      addNodeGroupEntity.setCpuNum(ng.getCpuNum());
      addNodeGroupEntity.setMemorySize(ng.getMemCapacityMB());
      addNodeGroupEntity.setHaFlag(ng.getHaFlag());
      if (null != ng.getStorage()) {
        if (ng.getStorage().getType().equals(Datastore.DatastoreType.SHARED.toString())) {
          addNodeGroupEntity.setStorageType(Datastore.DatastoreType.SHARED);
        }
 else         if (ng.getStorage().getType().equals(Datastore.DatastoreType.LOCAL.toString())) {
          addNodeGroupEntity.setStorageType(Datastore.DatastoreType.LOCAL);
        }
        addNodeGroupEntity.setStorageSize(ng.getStorage().getSizeGB());
        addNodeGroupEntity.setVcDatastoreNameList(ng.getStorage().getDsNames());
        addNodeGroupEntity.setDdDatastoreNameList(ng.getStorage().getDsNames4Data());
        addNodeGroupEntity.setSdDatastoreNameList(ng.getStorage().getDsNames4System());
      }
      addNodeGroupEntity.setGroupRacks(ng.getReferredGroup());
      addNodeGroupEntity.setHadoopConfig((new Gson()).toJson(ng.getConfiguration()));
      addNodeGroupEntity.setCluster(clusterEntity);
      addNodeGroupEntity.setVmFolderPath(clusterEntity);
      ng.setVmFolderPath(clusterEntity.getRootFolder() + "String_Node_Str" + ng.getName());
      logger.info("String_Node_Str" + ng.getName() + "String_Node_Str"+ clusterName+ "String_Node_Str");
      clusterEntityMgr.insert(addNodeGroupEntity);
    }
 else {
      logger.error("String_Node_Str" + ng.getName() + "String_Node_Str"+ clusterName+ "String_Node_Str");
      throw ClusterManagerException.NODE_GROUP_HAS_EXISTED(clusterName,ng.getName());
    }
    node.setCluster(clusterSpec);
    node.setTargetVcCluster(clusterSpec.getVcClusters().get(0).getName());
    node.setNodeGroup(ng);
    node.setTargetRp(rpNames);
    vNodes.add(node);
  }
  clusterEntityMgr.updateClusterStatus(clusterName,ClusterStatus.ADDING);
  if (clusteringService.addNodeGroups(clusterSpec,nodeGroupsAdd,vNodes)) {
    taskId=resumeClusterCreation(clusterName);
  }
 else {
    logger.error("String_Node_Str" + clusterName + "String_Node_Str");
    clusterEntityMgr.updateClusterStatus(clusterName,ClusterStatus.PROVISION_ERROR);
    throw ClusterManagerException.ADD_NODE_GROUP_FAILED(clusterName);
  }
  return taskId;
}

Fixed version (ground truth):
@ClusterManagerPointcut public Long addCluster(String clusterName,NodeGroupCreate[] nodeGroupsAdd) throws Exception {
  Long taskId=null;
  List<BaseNode> vNodes=new ArrayList<BaseNode>();
  String rpNames=null;
  ClusterCreate clusterSpec=clusterConfigMgr.getClusterConfig(clusterName);
  List<NodeEntity> nodes=clusterEntityMgr.findAllNodes(clusterName);
  for (  NodeEntity node : nodes) {
    rpNames=node.getVcRp().getVcResourcePool();
    if (null != rpNames)     break;
  }
  clusterSpec.setNodeGroups(nodeGroupsAdd);
  for (  NodeGroupCreate ng : nodeGroupsAdd) {
    BaseNode node=new BaseNode();
    NodeGroupEntity group=clusterEntityMgr.findByName(clusterName,ng.getName());
    ClusterEntity clusterEntity=clusterEntityMgr.findByName(clusterName);
    if (clusterEntity == null) {
      throw ClusterConfigException.CLUSTER_CONFIG_NOT_FOUND(clusterName);
    }
    if (0 == ng.getInstanceNum()) {
      throw ClusterManagerException.NODE_GROUP_CANNOT_BE_ZERO(ng.getName());
    }
    if (group == null) {
      NodeGroupEntity addNodeGroupEntity=new NodeGroupEntity();
      addNodeGroupEntity.setName(ng.getName());
      addNodeGroupEntity.setRoles((new Gson()).toJson(ng.getRoles()));
      addNodeGroupEntity.setNodeType(ng.getInstanceType());
      addNodeGroupEntity.setDefineInstanceNum(ng.getInstanceNum());
      addNodeGroupEntity.setCpuNum(ng.getCpuNum());
      addNodeGroupEntity.setMemorySize(ng.getMemCapacityMB());
      addNodeGroupEntity.setHaFlag(ng.getHaFlag());
      if (null != ng.getStorage()) {
        if (ng.getStorage().getType().equals(Datastore.DatastoreType.SHARED.toString())) {
          addNodeGroupEntity.setStorageType(Datastore.DatastoreType.SHARED);
        }
 else         if (ng.getStorage().getType().equals(Datastore.DatastoreType.LOCAL.toString())) {
          addNodeGroupEntity.setStorageType(Datastore.DatastoreType.LOCAL);
        }
        addNodeGroupEntity.setStorageSize(ng.getStorage().getSizeGB());
        addNodeGroupEntity.setVcDatastoreNameList(ng.getStorage().getDsNames());
        addNodeGroupEntity.setDdDatastoreNameList(ng.getStorage().getDsNames4Data());
        addNodeGroupEntity.setSdDatastoreNameList(ng.getStorage().getDsNames4System());
      }
      addNodeGroupEntity.setGroupRacks(ng.getReferredGroup());
      addNodeGroupEntity.setHadoopConfig((new Gson()).toJson(ng.getConfiguration()));
      addNodeGroupEntity.setCluster(clusterEntity);
      addNodeGroupEntity.setVmFolderPath(clusterEntity);
      ng.setVmFolderPath(clusterEntity.getRootFolder() + "String_Node_Str" + ng.getName());
      logger.info("String_Node_Str" + ng.getName() + "String_Node_Str"+ clusterName+ "String_Node_Str");
      clusterEntityMgr.insert(addNodeGroupEntity);
    }
 else {
      logger.error("String_Node_Str" + ng.getName() + "String_Node_Str"+ clusterName+ "String_Node_Str");
      throw ClusterManagerException.NODE_GROUP_HAS_EXISTED(clusterName,ng.getName());
    }
    node.setCluster(clusterSpec);
    node.setTargetVcCluster(clusterSpec.getVcClusters().get(0).getName());
    node.setNodeGroup(ng);
    node.setTargetRp(rpNames);
    vNodes.add(node);
  }
  clusterEntityMgr.updateClusterStatus(clusterName,ClusterStatus.ADDING);
  if (clusteringService.addNodeGroups(clusterSpec,nodeGroupsAdd,vNodes)) {
    taskId=clusterAddExecute(clusterName,nodeGroupsAdd);
  }
 else {
    logger.error("String_Node_Str" + clusterName + "String_Node_Str");
    clusterEntityMgr.updateClusterStatus(clusterName,ClusterStatus.PROVISION_ERROR);
    throw ClusterManagerException.ADD_NODE_GROUP_FAILED(clusterName);
  }
  return taskId;
}