Program: 49020
Project: 49020
Buggy source:
public Long resizeCluster(String clusterName,String nodeGroupName,int instanceNum) throws Exception {
  logger.info("String_Node_Str" + nodeGroupName + "String_Node_Str"+ clusterName+ "String_Node_Str"+ instanceNum);
  ClusterEntity cluster=clusterEntityMgr.findByName(clusterName);
  if (cluster == null) {
    logger.error("String_Node_Str" + clusterName + "String_Node_Str");
    throw BddException.NOT_FOUND("String_Node_Str",clusterName);
  }
  List<String> dsNames=getUsedDS(cluster.getVcDatastoreNameList());
  if (dsNames.isEmpty()) {
    throw ClusterConfigException.NO_RESOURCE_POOL_ADDED();
  }
  List<VcCluster> vcClusters=getUsedVcClusters(cluster.getVcRpNameList());
  if (vcClusters.isEmpty()) {
    throw ClusterConfigException.NO_DATASTORE_ADDED();
  }
  validateDatastore(dsNames,vcClusters);
  validateNetworkAccessibility(clusterName,cluster.getNetwork().getName(),vcClusters);
  NodeGroupEntity group=clusterEntityMgr.findByName(cluster,nodeGroupName);
  if (group == null) {
    logger.error("String_Node_Str" + nodeGroupName + "String_Node_Str"+ clusterName+ "String_Node_Str");
    throw ClusterManagerException.NODEGROUP_NOT_FOUND_ERROR(nodeGroupName);
  }
  List<String> roles=group.getRoleNameList();
  List<String> unsupportedRoles=new ArrayList<String>();
  AuAssert.check(!roles.isEmpty(),"String_Node_Str");
  if (roles.contains(HadoopRole.HADOOP_NAMENODE_ROLE.toString())) {
    unsupportedRoles.add(HadoopRole.HADOOP_NAMENODE_ROLE.toString());
  }
  if (roles.contains(HadoopRole.HADOOP_JOBTRACKER_ROLE.toString())) {
    unsupportedRoles.add(HadoopRole.HADOOP_JOBTRACKER_ROLE.toString());
  }
  if (roles.contains(HadoopRole.ZOOKEEPER_ROLE.toString())) {
    unsupportedRoles.add(HadoopRole.ZOOKEEPER_ROLE.toString());
  }
  if (!unsupportedRoles.isEmpty()) {
    logger.info("String_Node_Str" + unsupportedRoles);
    throw ClusterManagerException.ROLES_NOT_SUPPORTED(unsupportedRoles);
  }
  if (!ClusterStatus.RUNNING.equals(cluster.getStatus())) {
    logger.error("String_Node_Str" + clusterName + "String_Node_Str"+ cluster.getStatus()+ "String_Node_Str");
    throw ClusterManagerException.UPDATE_NOT_ALLOWED_ERROR(clusterName,"String_Node_Str");
  }
  if (instanceNum <= group.getDefineInstanceNum()) {
    logger.error("String_Node_Str" + nodeGroupName + "String_Node_Str"+ group.getDefineInstanceNum()+ "String_Node_Str"+ instanceNum+ "String_Node_Str");
    throw ClusterManagerException.SHRINK_OP_NOT_SUPPORTED(nodeGroupName,instanceNum,group.getDefineInstanceNum());
  }
  Integer instancePerHost=group.getInstancePerHost();
  if (instancePerHost != null && instanceNum % instancePerHost != 0) {
    throw BddException.INVALID_PARAMETER("String_Node_Str",new StringBuilder(100).append(instanceNum).append("String_Node_Str").toString());
  }
  ValidationUtils.validHostNumber(clusterEntityMgr,group,instanceNum);
  ValidationUtils.hasEnoughHost(rackDao,group,instanceNum);
  int oldInstanceNum=group.getDefineInstanceNum();
  group.setDefineInstanceNum(instanceNum);
  clusterEntityMgr.update(group);
  Map<String,JobParameter> param=new TreeMap<String,JobParameter>();
  param.put(JobConstants.CLUSTER_NAME_JOB_PARAM,new JobParameter(clusterName));
  param.put(JobConstants.GROUP_NAME_JOB_PARAM,new JobParameter(nodeGroupName));
  param.put(JobConstants.GROUP_INSTANCE_NEW_NUMBER_JOB_PARAM,new JobParameter(Long.valueOf(instanceNum)));
  param.put(JobConstants.GROUP_INSTANCE_OLD_NUMBER_JOB_PARAM,new JobParameter(Long.valueOf(oldInstanceNum)));
  param.put(JobConstants.TIMESTAMP_JOB_PARAM,new JobParameter(new Date()));
  param.put(JobConstants.CLUSTER_SUCCESS_STATUS_JOB_PARAM,new JobParameter(ClusterStatus.RUNNING.name()));
  param.put(JobConstants.CLUSTER_FAILURE_STATUS_JOB_PARAM,new JobParameter(ClusterStatus.RUNNING.name()));
  param.put(JobConstants.VERIFY_NODE_STATUS_SCOPE_PARAM,new JobParameter(JobConstants.GROUP_NODE_SCOPE_VALUE));
  JobParameters jobParameters=new JobParameters(param);
  clusterEntityMgr.updateClusterStatus(clusterName,ClusterStatus.UPDATING);
  try {
    return jobManager.runJob(JobConstants.RESIZE_CLUSTER_JOB_NAME,jobParameters);
  }
 catch (  Exception e) {
    logger.error("String_Node_Str" + clusterName,e);
    clusterEntityMgr.updateClusterStatus(clusterName,ClusterStatus.RUNNING);
    group.setDefineInstanceNum(oldInstanceNum);
    clusterEntityMgr.update(group);
    throw e;
  }
}

Fixed version (ground truth):
public Long resizeCluster(String clusterName,String nodeGroupName,int instanceNum) throws Exception {
  logger.info("String_Node_Str" + nodeGroupName + "String_Node_Str"+ clusterName+ "String_Node_Str"+ instanceNum);
  ClusterEntity cluster=clusterEntityMgr.findByName(clusterName);
  if (cluster == null) {
    logger.error("String_Node_Str" + clusterName + "String_Node_Str");
    throw BddException.NOT_FOUND("String_Node_Str",clusterName);
  }
  List<String> dsNames=getUsedDS(cluster.getVcDatastoreNameList());
  if (dsNames.isEmpty()) {
    throw ClusterConfigException.NO_RESOURCE_POOL_ADDED();
  }
  List<VcCluster> vcClusters=getUsedVcClusters(cluster.getVcRpNameList());
  if (vcClusters.isEmpty()) {
    throw ClusterConfigException.NO_DATASTORE_ADDED();
  }
  validateDatastore(dsNames,vcClusters);
  validateNetworkAccessibility(clusterName,cluster.getNetwork().getName(),vcClusters);
  NodeGroupEntity group=clusterEntityMgr.findByName(cluster,nodeGroupName);
  if (group == null) {
    logger.error("String_Node_Str" + nodeGroupName + "String_Node_Str"+ clusterName+ "String_Node_Str");
    throw ClusterManagerException.NODEGROUP_NOT_FOUND_ERROR(nodeGroupName);
  }
  List<String> roles=group.getRoleNameList();
  List<String> unsupportedRoles=new ArrayList<String>();
  AuAssert.check(!roles.isEmpty(),"String_Node_Str");
  if (roles.contains(HadoopRole.HADOOP_NAMENODE_ROLE.toString())) {
    unsupportedRoles.add(HadoopRole.HADOOP_NAMENODE_ROLE.toString());
  }
  if (roles.contains(HadoopRole.HADOOP_JOBTRACKER_ROLE.toString())) {
    unsupportedRoles.add(HadoopRole.HADOOP_JOBTRACKER_ROLE.toString());
  }
  if (roles.contains(HadoopRole.ZOOKEEPER_ROLE.toString())) {
    unsupportedRoles.add(HadoopRole.ZOOKEEPER_ROLE.toString());
  }
  if (!unsupportedRoles.isEmpty()) {
    logger.info("String_Node_Str" + unsupportedRoles);
    throw ClusterManagerException.ROLES_NOT_SUPPORTED(unsupportedRoles);
  }
  if (!ClusterStatus.RUNNING.equals(cluster.getStatus())) {
    logger.error("String_Node_Str" + clusterName + "String_Node_Str"+ cluster.getStatus()+ "String_Node_Str");
    throw ClusterManagerException.UPDATE_NOT_ALLOWED_ERROR(clusterName,"String_Node_Str");
  }
  if (instanceNum <= group.getDefineInstanceNum()) {
    logger.error("String_Node_Str" + nodeGroupName + "String_Node_Str"+ group.getDefineInstanceNum()+ "String_Node_Str"+ instanceNum+ "String_Node_Str");
    throw ClusterManagerException.SHRINK_OP_NOT_SUPPORTED(nodeGroupName,instanceNum,group.getDefineInstanceNum());
  }
  Integer instancePerHost=group.getInstancePerHost();
  if (instancePerHost != null && instanceNum % instancePerHost != 0) {
    throw BddException.INVALID_PARAMETER("String_Node_Str",new StringBuilder(100).append(instanceNum).append("String_Node_Str").toString());
  }
  ValidationUtils.validHostNumber(clusterEntityMgr,group,instanceNum);
  ValidationUtils.hasEnoughHost(rackInfoMgr,clusterEntityMgr,group,instanceNum);
  int oldInstanceNum=group.getDefineInstanceNum();
  group.setDefineInstanceNum(instanceNum);
  clusterEntityMgr.update(group);
  Map<String,JobParameter> param=new TreeMap<String,JobParameter>();
  param.put(JobConstants.CLUSTER_NAME_JOB_PARAM,new JobParameter(clusterName));
  param.put(JobConstants.GROUP_NAME_JOB_PARAM,new JobParameter(nodeGroupName));
  param.put(JobConstants.GROUP_INSTANCE_NEW_NUMBER_JOB_PARAM,new JobParameter(Long.valueOf(instanceNum)));
  param.put(JobConstants.GROUP_INSTANCE_OLD_NUMBER_JOB_PARAM,new JobParameter(Long.valueOf(oldInstanceNum)));
  param.put(JobConstants.TIMESTAMP_JOB_PARAM,new JobParameter(new Date()));
  param.put(JobConstants.CLUSTER_SUCCESS_STATUS_JOB_PARAM,new JobParameter(ClusterStatus.RUNNING.name()));
  param.put(JobConstants.CLUSTER_FAILURE_STATUS_JOB_PARAM,new JobParameter(ClusterStatus.RUNNING.name()));
  param.put(JobConstants.VERIFY_NODE_STATUS_SCOPE_PARAM,new JobParameter(JobConstants.GROUP_NODE_SCOPE_VALUE));
  JobParameters jobParameters=new JobParameters(param);
  clusterEntityMgr.updateClusterStatus(clusterName,ClusterStatus.UPDATING);
  try {
    return jobManager.runJob(JobConstants.RESIZE_CLUSTER_JOB_NAME,jobParameters);
  }
 catch (  Exception e) {
    logger.error("String_Node_Str" + clusterName,e);
    clusterEntityMgr.updateClusterStatus(clusterName,ClusterStatus.RUNNING);
    group.setDefineInstanceNum(oldInstanceNum);
    clusterEntityMgr.update(group);
    throw e;
  }
}