Program: 49031
Project: 49031
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)) {
    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);
    if (cluster.containsComputeOnlyNodeGroups()) {
      clusterEntity.setAutomationEnable(automationEnable);
    }
 else {
      clusterEntity.setAutomationEnable(null);
    }
    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");
    }
    String networkName=cluster.getNetworkName();
    NetworkEntity networkEntity=null;
    if (networkName == null || networkName.isEmpty()) {
      List<NetworkEntity> nets=networkMgr.getAllNetworkEntities();
      if (nets.isEmpty() || nets.size() > 1) {
        throw ClusterConfigException.NETWORK_IS_NOT_SPECIFIED(nets.size(),name);
      }
 else {
        networkEntity=nets.get(0);
      }
    }
 else {
      networkEntity=networkMgr.getNetworkEntityByName(networkName);
    }
    if (networkEntity == null) {
      throw ClusterConfigException.NETWORK_IS_NOT_FOUND(networkName,name);
    }
    clusterEntity.setNetwork(networkEntity);
    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()));
    }
    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>();
  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)) {
    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);
    if (cluster.containsComputeOnlyNodeGroups()) {
      clusterEntity.setAutomationEnable(automationEnable);
    }
 else {
      clusterEntity.setAutomationEnable(null);
    }
    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");
    }
    String networkName=cluster.getNetworkName();
    NetworkEntity networkEntity=null;
    if (networkName == null || networkName.isEmpty()) {
      List<NetworkEntity> nets=networkMgr.getAllNetworkEntities();
      if (nets.isEmpty() || nets.size() > 1) {
        throw ClusterConfigException.NETWORK_IS_NOT_SPECIFIED(nets.size(),name);
      }
 else {
        networkEntity=nets.get(0);
      }
    }
 else {
      networkEntity=networkMgr.getNetworkEntityByName(networkName);
    }
    if (networkEntity == null) {
      throw ClusterConfigException.NETWORK_IS_NOT_FOUND(networkName,name);
    }
    clusterEntity.setNetwork(networkEntity);
    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()));
    }
    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);
  }
}