Program: 49085
Project: 49085
Buggy source:
public ClusterEntity createClusterConfig(final ClusterCreate cluster){
  final 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.validateNodeGroupPlacementPolicies(failedMsgList,warningMsgList)) {
    throw ClusterConfigException.INVALID_PLACEMENT_POLICIES(failedMsgList);
  }
  if (!validateRacksInfo(cluster,failedMsgList)) {
    throw ClusterConfigException.INVALID_PLACEMENT_POLICIES(failedMsgList);
  }
  if (!cluster.validateNodeGroupRoles(failedMsgList)) {
    throw ClusterConfigException.INVALID_ROLES(failedMsgList);
  }
  if (cluster.getDistro() == null || distroMgr.getDistroByName(cluster.getDistro()) == null) {
    throw BddException.INVALID_PARAMETER("String_Node_Str",cluster.getDistro());
  }
  transformHDFSUrl(cluster);
  try {
    return DAL.inTransactionDo(new Saveable<ClusterEntity>(){
      public ClusterEntity body(){
        ClusterEntity entity=ClusterEntity.findClusterEntityByName(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.setStartAfterDeploy(true);
        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");
          Set<String> globalNames=rpMgr.getAllRPNames();
          if (globalNames.isEmpty()) {
            throw ClusterConfigException.NO_RESOURCE_POOL_ADDED();
          }
          List<String> rpNames=new ArrayList<String>();
          rpNames.addAll(globalNames);
          clusterEntity.setVcRpNameList(rpNames);
        }
        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");
          Set<String> globalNames=datastoreMgr.getAllDataStoreName();
          if (globalNames.isEmpty()) {
            throw ClusterConfigException.NO_DATASTORE_ADDED();
          }
          List<String> dsNames=new ArrayList<String>();
          dsNames.addAll(globalNames);
          clusterEntity.setVcDatastoreNameList(dsNames);
        }
        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()));
        }
        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");
          }
        }
        clusterEntity.insert();
        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):
public ClusterEntity createClusterConfig(final ClusterCreate cluster){
  final 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.validateNodeGroupPlacementPolicies(failedMsgList,warningMsgList)) {
    throw ClusterConfigException.INVALID_PLACEMENT_POLICIES(failedMsgList);
  }
  if (!validateRacksInfo(cluster,failedMsgList)) {
    throw ClusterConfigException.INVALID_PLACEMENT_POLICIES(failedMsgList);
  }
  if (!cluster.validateNodeGroupRoles(failedMsgList)) {
    throw ClusterConfigException.INVALID_ROLES(failedMsgList);
  }
  if (cluster.getDistro() == null || distroMgr.getDistroByName(cluster.getDistro()) == null) {
    throw BddException.INVALID_PARAMETER("String_Node_Str",cluster.getDistro());
  }
  transformHDFSUrl(cluster);
  try {
    return DAL.inTransactionDo(new Saveable<ClusterEntity>(){
      public ClusterEntity body(){
        ClusterEntity entity=ClusterEntity.findClusterEntityByName(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.setStartAfterDeploy(true);
        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()));
        }
        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");
          }
        }
        clusterEntity.insert();
        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);
  }
}