Program: 48618
Project: 48618
Buggy source:
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=null;
  if (clusterEntity.getAppManager() == null) {
    enumRoles=getEnumRoles(group.getRoles(),distro);
    if (enumRoles.isEmpty()) {
      throw ClusterConfigException.NO_HADOOP_ROLE_SPECIFIED(group.getName());
    }
    if (enumRoles.contains(HadoopRole.CUSTOMIZED_ROLE)) {
      groupEntity.setRoles(gson.toJson(roles));
    }
 else {
      List<String> sortedRolesByDependency=new ArrayList<String>();
      sortedRolesByDependency.addAll(roles);
      Collections.sort(sortedRolesByDependency,new RoleComparactor());
      groupEntity.setRoles(gson.toJson(sortedRolesByDependency));
    }
  }
 else {
    groupEntity.setRoles(gson.toJson(roles));
  }
  if (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();
  }
  if (clusterEntity.getAppManager() == null) {
    GroupType groupType=GroupType.fromHadoopRole(enumRoles);
    CommonClusterExpandPolicy.expandGroupInstanceType(groupEntity,groupType,sharedPattern,localPattern);
  }
  groupEntity.setHaFlag(group.getHaFlag());
  if (group.getConfiguration() != null && group.getConfiguration().size() > 0) {
    if (clusterEntity.getAppManager() == null) {
      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=null;
  if (clusterEntity.getAppManager() == null || Constants.IRONFAN.equalsIgnoreCase(clusterEntity.getAppManager())) {
    enumRoles=getEnumRoles(group.getRoles(),distro);
    if (enumRoles.isEmpty()) {
      throw ClusterConfigException.NO_HADOOP_ROLE_SPECIFIED(group.getName());
    }
    if (enumRoles.contains(HadoopRole.CUSTOMIZED_ROLE)) {
      groupEntity.setRoles(gson.toJson(roles));
    }
 else {
      List<String> sortedRolesByDependency=new ArrayList<String>();
      sortedRolesByDependency.addAll(roles);
      Collections.sort(sortedRolesByDependency,new RoleComparactor());
      groupEntity.setRoles(gson.toJson(sortedRolesByDependency));
    }
  }
 else {
    groupEntity.setRoles(gson.toJson(roles));
  }
  if (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();
  }
  if (clusterEntity.getAppManager() == null || Constants.IRONFAN.equalsIgnoreCase(clusterEntity.getAppManager())) {
    GroupType groupType=GroupType.fromHadoopRole(enumRoles);
    CommonClusterExpandPolicy.expandGroupInstanceType(groupEntity,groupType,sharedPattern,localPattern);
  }
  groupEntity.setHaFlag(group.getHaFlag());
  if (group.getConfiguration() != null && group.getConfiguration().size() > 0) {
    if (clusterEntity.getAppManager() == null || Constants.IRONFAN.equalsIgnoreCase(clusterEntity.getAppManager())) {
      CommonClusterExpandPolicy.validateAppConfig(group.getConfiguration(),validateWhiteList);
    }
    groupEntity.setHadoopConfig(gson.toJson(group.getConfiguration()));
  }
  groupEntity.setVmFolderPath(clusterEntity);
  logger.debug("String_Node_Str" + group.getName());
  return groupEntity;
}