Program: 49060
Project: 49060
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);
  groupEntity.setCpuNum(group.getCpuNum());
  groupEntity.setDefineInstanceNum(group.getInstanceNum());
  groupEntity.setMemorySize(group.getMemCapacityMB());
  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 TreeSet<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());
  }
  if (group.getStorage() != null) {
    groupEntity.setStorageSize(group.getStorage().getSizeGB());
    List<String> groupRoles=group.getRoles();
    if (groupRoles.contains(HadoopRole.ZOOKEEPER_ROLE.toString()) && groupRoles.size() == 1) {
      groupEntity.setDiskBisect(true);
    }
 else {
      groupEntity.setDiskBisect(false);
    }
    String storageType=group.getStorage().getType();
    if (storageType != null) {
      if (storageType.equals(DatastoreType.TEMPFS.name())) {
        groupEntity.setStorageType(DatastoreType.TEMPFS);
        roles.add(HadoopRole.TEMPFS_CLIENT_ROLE.toString());
      }
 else       if (storageType.equals(DatastoreType.LOCAL.name())) {
        groupEntity.setStorageType(DatastoreType.LOCAL);
      }
 else {
        groupEntity.setStorageType(DatastoreType.SHARED);
      }
    }
    groupEntity.setVcDatastoreNameList(group.getStorage().getDsNames());
  }
  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);
  boolean removeIt=validateGroupInstanceNum(clusterEntity.getName(),groupType,group,allRoles);
  if (removeIt) {
    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,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);
  groupEntity.setCpuNum(group.getCpuNum());
  groupEntity.setDefineInstanceNum(group.getInstanceNum());
  groupEntity.setMemorySize(group.getMemCapacityMB());
  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 TreeSet<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());
  }
  if (group.getStorage() != null) {
    groupEntity.setStorageSize(group.getStorage().getSizeGB());
    List<String> groupRoles=group.getRoles();
    if (groupRoles.contains(HadoopRole.ZOOKEEPER_ROLE.toString()) && groupRoles.size() == 1) {
      groupEntity.setDiskBisect(true);
    }
 else {
      groupEntity.setDiskBisect(false);
    }
    String storageType=group.getStorage().getType();
    if (storageType != null) {
      if (storageType.equalsIgnoreCase(DatastoreType.TEMPFS.name())) {
        groupEntity.setStorageType(DatastoreType.TEMPFS);
        roles.add(HadoopRole.TEMPFS_CLIENT_ROLE.toString());
      }
 else       if (storageType.equalsIgnoreCase(DatastoreType.LOCAL.name())) {
        groupEntity.setStorageType(DatastoreType.LOCAL);
      }
 else {
        groupEntity.setStorageType(DatastoreType.SHARED);
      }
    }
    groupEntity.setVcDatastoreNameList(group.getStorage().getDsNames());
  }
  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);
  boolean removeIt=validateGroupInstanceNum(clusterEntity.getName(),groupType,group,allRoles);
  if (removeIt) {
    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;
}