Program: 48635
Project: 48635
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>();
  DistroRead distro=distroMgr.getDistroByName(cluster.getDistro());
  if (cluster.getDistro() == null || distro == null) {
    throw BddException.INVALID_PARAMETER("String_Node_Str",cluster.getDistro());
  }
  String appManager=cluster.getAppManager();
  if (appManager == null) {
    appManager=new String("String_Node_Str");
  }
  SoftwareManager softwareManager=softwareManagerCollector.getSoftwareManager(appManager);
  if (softwareManager == null) {
    logger.error("String_Node_Str");
    throw new ClusterConfigException(null,"String_Node_Str");
  }
  try {
    softwareManager.validateRoles(cluster.toBlueprint(),distro.getRoles());
    cluster.validateClusterCreate(failedMsgList,warningMsgList);
  }
 catch (  SoftwareManagementPluginException e) {
    failedMsgList.add(e.getFailedMsgList().toString());
  }
  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.setAppManagerName(cluster.getAppManager());
    clusterEntity.setDistro(cluster.getDistro());
    clusterEntity.setDistroVendor(cluster.getDistroVendor());
    clusterEntity.setDistroVersion(cluster.getDistroVersion());
    clusterEntity.setAppManager(cluster.getAppManager());
    clusterEntity.setStartAfterDeploy(true);
    clusterEntity.setPassword(cluster.getPassword());
    clusterEntity.setVersion(clusterEntityMgr.getServerVersion());
    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(validateAndConvertNetNamesToNetConfigs(cluster.getNetworkConfig(),cluster.getDistroVendor().equalsIgnoreCase(Constants.MAPR_VENDOR)));
    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,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());
  }
  String appManager=cluster.getAppManager();
  if (appManager == null) {
    appManager=new String("String_Node_Str");
  }
  SoftwareManager softwareManager=softwareManagerCollector.getSoftwareManager(appManager);
  if (softwareManager == null) {
    logger.error("String_Node_Str");
    throw new ClusterConfigException(null,"String_Node_Str");
  }
  try {
    softwareManager.validateRoles(cluster.toBlueprint(),distro.getRoles());
    cluster.validateClusterCreate(failedMsgList,warningMsgList);
  }
 catch (  SoftwareManagementPluginException e) {
    failedMsgList.add(e.getFailedMsgList().toString());
  }
  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.setAppManager(cluster.getAppManager());
    clusterEntity.setDistro(cluster.getDistro());
    clusterEntity.setDistroVendor(cluster.getDistroVendor());
    clusterEntity.setDistroVersion(cluster.getDistroVersion());
    clusterEntity.setAppManager(cluster.getAppManager());
    clusterEntity.setStartAfterDeploy(true);
    clusterEntity.setPassword(cluster.getPassword());
    clusterEntity.setVersion(clusterEntityMgr.getServerVersion());
    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(validateAndConvertNetNamesToNetConfigs(cluster.getNetworkConfig(),cluster.getDistroVendor().equalsIgnoreCase(Constants.MAPR_VENDOR)));
    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,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);
  }
}