Program: 48730
Project: 48730
Buggy source:
private NodeGroupEntity convertGroup(Gson gson,ClusterEntity clusterEntity,EnumSet<HadoopRole> allRoles,NodeGroupCreate group,String distro,boolean validateWhiteList){
  NodeGroupEntity groupEntity=new NodeGroupEntity();
  if (group.getRoles() == null || group.getRoles().isEmpty()) {
    throw ClusterConfigException.NO_HADOOP_ROLE_SPECIFIED(group.getName());
  }
  Set<String> roles=new HashSet<String>();
  groupEntity.setCluster(clusterEntity);
  int cpuNum=group.getCpuNum() == null ? 0 : group.getCpuNum();
  if (!VcVmUtil.validateCPU(clusteringService.getTemplateVmId(),cpuNum)) {
    throw VcProviderException.CPU_NUM_NOT_MULTIPLE_OF_CORES_PER_SOCKET(group.getName(),clusteringService.getTemplateVmName());
  }
  groupEntity.setCpuNum(cpuNum);
  groupEntity.setDefineInstanceNum(group.getInstanceNum());
  groupEntity.setMemorySize(group.getMemCapacityMB() == null ? 0 : group.getMemCapacityMB());
  groupEntity.setSwapRatio(group.getSwapRatio());
  groupEntity.setName(group.getName());
  groupEntity.setNodeType(group.getInstanceType());
  PlacementPolicy policies=group.getPlacementPolicies();
  if (policies != null) {
    List<GroupAssociation> associons=policies.getGroupAssociations();
    if (associons != null) {
      Set<NodeGroupAssociation> associonEntities=new HashSet<NodeGroupAssociation>();
      for (      GroupAssociation a : associons) {
        NodeGroupAssociation ae=new NodeGroupAssociation();
        ae.setAssociationType(a.getType());
        ae.setNodeGroup(groupEntity);
        ae.setReferencedGroup(a.getReference());
        associonEntities.add(ae);
      }
      groupEntity.setGroupAssociations(associonEntities);
    }
    if (policies.getInstancePerHost() != null) {
      groupEntity.setInstancePerHost(policies.getInstancePerHost());
    }
    if (policies.getGroupRacks() != null) {
      groupEntity.setGroupRacks((new Gson()).toJson(policies.getGroupRacks()));
    }
  }
  if (group.getRpNames() != null && group.getRpNames().size() > 0) {
    groupEntity.setVcRpNameList(group.getRpNames());
  }
  convertStorage(group,groupEntity,roles);
  roles.addAll(group.getRoles());
  List<String> sortedRolesByDependency=new ArrayList<String>();
  sortedRolesByDependency.addAll(roles);
  Collections.sort(sortedRolesByDependency,new RoleComparactor());
  EnumSet<HadoopRole> enumRoles=getEnumRoles(group.getRoles(),distro);
  if (enumRoles.isEmpty()) {
    throw ClusterConfigException.NO_HADOOP_ROLE_SPECIFIED(group.getName());
  }
  groupEntity.setRoles(gson.toJson(sortedRolesByDependency));
  GroupType groupType=GroupType.fromHadoopRole(enumRoles);
  if (groupType == GroupType.CLIENT_GROUP && group.getInstanceNum() <= 0) {
    logger.warn("String_Node_Str" + group.getName() + "String_Node_Str");
    return null;
  }
  allRoles.addAll(enumRoles);
  List<String> dsNames=groupEntity.getVcDatastoreNameList();
  if (dsNames == null) {
    dsNames=clusterEntity.getVcDatastoreNameList();
  }
  Set<String> sharedPattern;
  Set<String> localPattern;
  if (dsNames != null) {
    sharedPattern=datastoreMgr.getSharedDatastoresByNames(dsNames);
    localPattern=datastoreMgr.getLocalDatastoresByNames(dsNames);
  }
 else {
    sharedPattern=datastoreMgr.getAllSharedDatastores();
    localPattern=datastoreMgr.getAllLocalDatastores();
  }
  CommonClusterExpandPolicy.expandGroupInstanceType(groupEntity,groupType,sharedPattern,localPattern);
  groupEntity.setHaFlag(group.getHaFlag());
  if (group.getConfiguration() != null && group.getConfiguration().size() > 0) {
    CommonClusterExpandPolicy.validateAppConfig(group.getConfiguration(),validateWhiteList);
    groupEntity.setHadoopConfig(gson.toJson(group.getConfiguration()));
  }
  groupEntity.setVmFolderPath(clusterEntity);
  logger.debug("String_Node_Str" + group.getName());
  return groupEntity;
}

Fixed version (ground truth):
private NodeGroupEntity convertGroup(Gson gson,ClusterEntity clusterEntity,NodeGroupCreate group,String distro,boolean validateWhiteList){
  NodeGroupEntity groupEntity=new NodeGroupEntity();
  if (group.getRoles() == null || group.getRoles().isEmpty()) {
    throw ClusterConfigException.NO_HADOOP_ROLE_SPECIFIED(group.getName());
  }
  groupEntity.setCluster(clusterEntity);
  int cpuNum=group.getCpuNum() == null ? 0 : group.getCpuNum();
  if (!VcVmUtil.validateCPU(clusteringService.getTemplateVmId(),cpuNum)) {
    throw VcProviderException.CPU_NUM_NOT_MULTIPLE_OF_CORES_PER_SOCKET(group.getName(),clusteringService.getTemplateVmName());
  }
  groupEntity.setCpuNum(cpuNum);
  groupEntity.setDefineInstanceNum(group.getInstanceNum());
  groupEntity.setMemorySize(group.getMemCapacityMB() == null ? 0 : group.getMemCapacityMB());
  groupEntity.setSwapRatio(group.getSwapRatio());
  groupEntity.setName(group.getName());
  groupEntity.setNodeType(group.getInstanceType());
  PlacementPolicy policies=group.getPlacementPolicies();
  if (policies != null) {
    List<GroupAssociation> associons=policies.getGroupAssociations();
    if (associons != null) {
      Set<NodeGroupAssociation> associonEntities=new HashSet<NodeGroupAssociation>();
      for (      GroupAssociation a : associons) {
        NodeGroupAssociation ae=new NodeGroupAssociation();
        ae.setAssociationType(a.getType());
        ae.setNodeGroup(groupEntity);
        ae.setReferencedGroup(a.getReference());
        associonEntities.add(ae);
      }
      groupEntity.setGroupAssociations(associonEntities);
    }
    if (policies.getInstancePerHost() != null) {
      groupEntity.setInstancePerHost(policies.getInstancePerHost());
    }
    if (policies.getGroupRacks() != null) {
      groupEntity.setGroupRacks((new Gson()).toJson(policies.getGroupRacks()));
    }
  }
  if (group.getRpNames() != null && group.getRpNames().size() > 0) {
    groupEntity.setVcRpNameList(group.getRpNames());
  }
  Set<String> roles=new LinkedHashSet<String>();
  convertStorage(group,groupEntity,roles);
  roles.addAll(group.getRoles());
  EnumSet<HadoopRole> enumRoles=getEnumRoles(group.getRoles(),distro);
  if (enumRoles.isEmpty()) {
    throw ClusterConfigException.NO_HADOOP_ROLE_SPECIFIED(group.getName());
  }
  groupEntity.setRoles(gson.toJson(roles));
  GroupType groupType=GroupType.fromHadoopRole(enumRoles);
  if (groupType == GroupType.CLIENT_GROUP && group.getInstanceNum() <= 0) {
    logger.warn("String_Node_Str" + group.getName() + "String_Node_Str");
    return null;
  }
  List<String> dsNames=groupEntity.getVcDatastoreNameList();
  if (dsNames == null) {
    dsNames=clusterEntity.getVcDatastoreNameList();
  }
  Set<String> sharedPattern;
  Set<String> localPattern;
  if (dsNames != null) {
    sharedPattern=datastoreMgr.getSharedDatastoresByNames(dsNames);
    localPattern=datastoreMgr.getLocalDatastoresByNames(dsNames);
  }
 else {
    sharedPattern=datastoreMgr.getAllSharedDatastores();
    localPattern=datastoreMgr.getAllLocalDatastores();
  }
  CommonClusterExpandPolicy.expandGroupInstanceType(groupEntity,groupType,sharedPattern,localPattern);
  groupEntity.setHaFlag(group.getHaFlag());
  if (group.getConfiguration() != null && group.getConfiguration().size() > 0) {
    CommonClusterExpandPolicy.validateAppConfig(group.getConfiguration(),validateWhiteList);
    groupEntity.setHadoopConfig(gson.toJson(group.getConfiguration()));
  }
  groupEntity.setVmFolderPath(clusterEntity);
  logger.debug("String_Node_Str" + group.getName());
  return groupEntity;
}