Program: 48884
Project: 48884
Buggy source:
@Transactional public ClusterEntity createClusterConfig(ClusterCreate cluster){
  String name=cluster.getName();
  if (name == null || name.isEmpty()) {
    throw ClusterConfigException.CLUSTER_NAME_MISSING();
  }
  List<String> failedMsgList=new ArrayList<String>();
  List<String> warningMsgList=new ArrayList<String>();
  if (cluster.getDistro() == null || distroMgr.getDistroByName(cluster.getDistro()) == null) {
    throw BddException.INVALID_PARAMETER("String_Node_Str",cluster.getDistro());
  }
  if (!cluster.getDistroVendor().equalsIgnoreCase(Constants.MAPR_VENDOR)) {
    List<String> allNetworkNames=new ArrayList<String>();
    for (    NetworkEntity entity : networkMgr.getAllNetworkEntities()) {
      allNetworkNames.add(entity.getName());
    }
    cluster.validateClusterCreate(failedMsgList,warningMsgList,distroMgr.getDistroByName(cluster.getDistro()).getRoles());
  }
  if (!failedMsgList.isEmpty()) {
    throw ClusterConfigException.INVALID_SPEC(failedMsgList);
  }
  if (!validateRacksInfo(cluster,failedMsgList)) {
    throw ClusterConfigException.INVALID_PLACEMENT_POLICIES(failedMsgList);
  }
  transformHDFSUrl(cluster);
  try {
    ClusterEntity entity=clusterEntityMgr.findByName(name);
    if (entity != null) {
      logger.info("String_Node_Str" + name + "String_Node_Str");
      throw BddException.ALREADY_EXISTS("String_Node_Str",name);
    }
    logger.debug("String_Node_Str" + name);
    Gson gson=new Gson();
    ClusterEntity clusterEntity=new ClusterEntity(name);
    clusterEntity.setDistro(cluster.getDistro());
    clusterEntity.setDistroVendor(cluster.getDistroVendor());
    clusterEntity.setDistroVersion(cluster.getDistroVersion());
    clusterEntity.setStartAfterDeploy(true);
    clusterEntity.setPassword(cluster.getPassword());
    if (cluster.containsComputeOnlyNodeGroups()) {
      clusterEntity.setAutomationEnable(automationEnable);
    }
 else {
      clusterEntity.setAutomationEnable(null);
    }
    clusterEntity.setVhmMinNum(-1);
    clusterEntity.setVhmMaxNum(-1);
    if (cluster.getRpNames() != null && cluster.getRpNames().size() > 0) {
      logger.debug("String_Node_Str" + cluster.getRpNames() + "String_Node_Str"+ name);
      clusterEntity.setVcRpNameList(cluster.getRpNames());
    }
 else {
      logger.debug("String_Node_Str");
    }
    if (cluster.getDsNames() != null && !cluster.getDsNames().isEmpty()) {
      logger.debug("String_Node_Str" + cluster.getDsNames() + "String_Node_Str"+ name);
      clusterEntity.setVcDatastoreNameList(cluster.getDsNames());
    }
 else {
      logger.debug("String_Node_Str");
    }
    clusterEntity.setNetworkConfig(convertNetNamesToNetConfigs(cluster.getNetworkConfig()));
    clusterEntity.setVhmJobTrackerPort("String_Node_Str");
    if (cluster.getConfiguration() != null && cluster.getConfiguration().size() > 0) {
      CommonClusterExpandPolicy.validateAppConfig(cluster.getConfiguration(),cluster.isValidateConfig());
      clusterEntity.setHadoopConfig((new Gson()).toJson(cluster.getConfiguration()));
      updateVhmJobTrackerPort(cluster,clusterEntity);
    }
    NodeGroupCreate[] groups=cluster.getNodeGroups();
    if (groups != null && groups.length > 0) {
      clusterEntity.setNodeGroups(convertNodeGroupsToEntities(gson,clusterEntity,cluster.getDistro(),groups,EnumSet.noneOf(HadoopRole.class),cluster.isValidateConfig()));
      validateMemorySize(clusterEntity.getNodeGroups(),failedMsgList);
      if (!failedMsgList.isEmpty()) {
        throw ClusterConfigException.INVALID_SPEC(failedMsgList);
      }
    }
    if (cluster.getTopologyPolicy() == null) {
      clusterEntity.setTopologyPolicy(TopologyType.NONE);
    }
 else {
      clusterEntity.setTopologyPolicy(cluster.getTopologyPolicy());
    }
    if (clusterEntity.getTopologyPolicy() == TopologyType.HVE) {
      boolean hveSupported=false;
      if (clusterEntity.getDistro() != null) {
        DistroRead dr=distroMgr.getDistroByName(clusterEntity.getDistro());
        if (dr != null) {
          hveSupported=dr.isHveSupported();
        }
      }
      if (!hveSupported) {
        throw ClusterConfigException.INVALID_TOPOLOGY_POLICY(clusterEntity.getTopologyPolicy(),"String_Node_Str");
      }
    }
    clusterEntityMgr.insert(clusterEntity);
    logger.debug("String_Node_Str" + name);
    return clusterEntity;
  }
 catch (  UniqueConstraintViolationException ex) {
    logger.info("String_Node_Str" + name + "String_Node_Str");
    throw BddException.ALREADY_EXISTS(ex,"String_Node_Str",name);
  }
}

Fixed version (ground truth):
@Transactional public ClusterEntity createClusterConfig(ClusterCreate cluster){
  String name=cluster.getName();
  if (name == null || name.isEmpty()) {
    throw ClusterConfigException.CLUSTER_NAME_MISSING();
  }
  List<String> failedMsgList=new ArrayList<String>();
  List<String> warningMsgList=new ArrayList<String>();
  DistroRead distro=distroMgr.getDistroByName(cluster.getDistro());
  if (cluster.getDistro() == null || distro == null) {
    throw BddException.INVALID_PARAMETER("String_Node_Str",cluster.getDistro());
  }
  if (!cluster.getDistroVendor().equalsIgnoreCase(Constants.MAPR_VENDOR)) {
    List<String> allNetworkNames=new ArrayList<String>();
    for (    NetworkEntity entity : networkMgr.getAllNetworkEntities()) {
      allNetworkNames.add(entity.getName());
    }
    cluster.validateClusterCreate(failedMsgList,warningMsgList,distro.getRoles());
  }
 else {
    cluster.validateClusterCreateOfMapr(failedMsgList,distro.getRoles());
  }
  if (!failedMsgList.isEmpty()) {
    throw ClusterConfigException.INVALID_SPEC(failedMsgList);
  }
  if (!validateRacksInfo(cluster,failedMsgList)) {
    throw ClusterConfigException.INVALID_PLACEMENT_POLICIES(failedMsgList);
  }
  transformHDFSUrl(cluster);
  try {
    ClusterEntity entity=clusterEntityMgr.findByName(name);
    if (entity != null) {
      logger.info("String_Node_Str" + name + "String_Node_Str");
      throw BddException.ALREADY_EXISTS("String_Node_Str",name);
    }
    logger.debug("String_Node_Str" + name);
    Gson gson=new Gson();
    ClusterEntity clusterEntity=new ClusterEntity(name);
    clusterEntity.setDistro(cluster.getDistro());
    clusterEntity.setDistroVendor(cluster.getDistroVendor());
    clusterEntity.setDistroVersion(cluster.getDistroVersion());
    clusterEntity.setStartAfterDeploy(true);
    clusterEntity.setPassword(cluster.getPassword());
    if (cluster.containsComputeOnlyNodeGroups()) {
      clusterEntity.setAutomationEnable(automationEnable);
    }
 else {
      clusterEntity.setAutomationEnable(null);
    }
    clusterEntity.setVhmMinNum(-1);
    clusterEntity.setVhmMaxNum(-1);
    if (cluster.getRpNames() != null && cluster.getRpNames().size() > 0) {
      logger.debug("String_Node_Str" + cluster.getRpNames() + "String_Node_Str"+ name);
      clusterEntity.setVcRpNameList(cluster.getRpNames());
    }
 else {
      logger.debug("String_Node_Str");
    }
    if (cluster.getDsNames() != null && !cluster.getDsNames().isEmpty()) {
      logger.debug("String_Node_Str" + cluster.getDsNames() + "String_Node_Str"+ name);
      clusterEntity.setVcDatastoreNameList(cluster.getDsNames());
    }
 else {
      logger.debug("String_Node_Str");
    }
    clusterEntity.setNetworkConfig(convertNetNamesToNetConfigs(cluster.getNetworkConfig()));
    clusterEntity.setVhmJobTrackerPort("String_Node_Str");
    if (cluster.getConfiguration() != null && cluster.getConfiguration().size() > 0) {
      CommonClusterExpandPolicy.validateAppConfig(cluster.getConfiguration(),cluster.isValidateConfig());
      clusterEntity.setHadoopConfig((new Gson()).toJson(cluster.getConfiguration()));
      updateVhmJobTrackerPort(cluster,clusterEntity);
    }
    NodeGroupCreate[] groups=cluster.getNodeGroups();
    if (groups != null && groups.length > 0) {
      clusterEntity.setNodeGroups(convertNodeGroupsToEntities(gson,clusterEntity,cluster.getDistro(),groups,EnumSet.noneOf(HadoopRole.class),cluster.isValidateConfig()));
      validateMemorySize(clusterEntity.getNodeGroups(),failedMsgList);
      if (!failedMsgList.isEmpty()) {
        throw ClusterConfigException.INVALID_SPEC(failedMsgList);
      }
    }
    if (cluster.getTopologyPolicy() == null) {
      clusterEntity.setTopologyPolicy(TopologyType.NONE);
    }
 else {
      clusterEntity.setTopologyPolicy(cluster.getTopologyPolicy());
    }
    if (clusterEntity.getTopologyPolicy() == TopologyType.HVE) {
      boolean hveSupported=false;
      if (clusterEntity.getDistro() != null) {
        DistroRead dr=distroMgr.getDistroByName(clusterEntity.getDistro());
        if (dr != null) {
          hveSupported=dr.isHveSupported();
        }
      }
      if (!hveSupported) {
        throw ClusterConfigException.INVALID_TOPOLOGY_POLICY(clusterEntity.getTopologyPolicy(),"String_Node_Str");
      }
    }
    clusterEntityMgr.insert(clusterEntity);
    logger.debug("String_Node_Str" + name);
    return clusterEntity;
  }
 catch (  UniqueConstraintViolationException ex) {
    logger.info("String_Node_Str" + name + "String_Node_Str");
    throw BddException.ALREADY_EXISTS(ex,"String_Node_Str",name);
  }
}