Program: 49077
Project: 49077
Buggy source:
public Long resizeCluster(final String clusterName,final String nodeGroupName,final int instanceNum) throws Exception {
  logger.info("String_Node_Str" + nodeGroupName + "String_Node_Str"+ clusterName+ "String_Node_Str"+ instanceNum);
  final ClusterEntity cluster=ClusterEntity.findClusterEntityByName(clusterName);
  if (cluster == null) {
    logger.error("String_Node_Str" + clusterName + "String_Node_Str");
    throw BddException.NOT_FOUND("String_Node_Str",clusterName);
  }
  final NodeGroupEntity group=DAL.inRoTransactionDo(new Saveable<NodeGroupEntity>(){
    @Override public NodeGroupEntity body() throws Exception {
      NodeGroupEntity group=NodeGroupEntity.findNodeGroupEntityByName(cluster,nodeGroupName);
      if (group == null) {
        logger.error("String_Node_Str" + nodeGroupName + "String_Node_Str"+ clusterName+ "String_Node_Str");
        throw ClusterManagerException.NOGEGROUP_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());
      }
      group.validateHostNumber(instanceNum);
      group.validateIfHostCanSatisfied(instanceNum);
      return group;
    }
  }
);
  final int oldInstanceNum=group.getDefineInstanceNum();
  group.setDefineInstanceNum(instanceNum);
  DAL.inTransactionUpdate(group);
  UpdateClusterListener listener=new UpdateClusterListener(clusterName);
  try {
    return createClusterMgmtTask(cluster,listener,ClusterStatus.UPDATING);
  }
 catch (  Exception ex) {
    DAL.inTransactionDo(new Saveable<Void>(){
      @Override public Void body(){
        DAL.refresh(group);
        group.setDefineInstanceNum(oldInstanceNum);
        Set<HadoopNodeEntity> toRemove=new HashSet<HadoopNodeEntity>();
        if (group.getHadoopNodes() != null) {
          for (          HadoopNodeEntity node : group.getHadoopNodes()) {
            if (ClusterCmdUtil.getIndexFromNodeName(node.getVmName()) >= oldInstanceNum) {
              logger.info("String_Node_Str" + node.getVmName());
              toRemove.add(node);
              DAL.delete(node);
            }
          }
          group.getHadoopNodes().removeAll(toRemove);
        }
        return null;
      }
    }
);
    throw ex;
  }
}

Fixed version (ground truth):
public Long resizeCluster(final String clusterName,final String nodeGroupName,final int instanceNum) throws Exception {
  logger.info("String_Node_Str" + nodeGroupName + "String_Node_Str"+ clusterName+ "String_Node_Str"+ instanceNum);
  final ClusterEntity cluster=ClusterEntity.findClusterEntityByName(clusterName);
  if (cluster == null) {
    logger.error("String_Node_Str" + clusterName + "String_Node_Str");
    throw BddException.NOT_FOUND("String_Node_Str",clusterName);
  }
  final NodeGroupEntity group=DAL.inRoTransactionDo(new Saveable<NodeGroupEntity>(){
    @Override public NodeGroupEntity body() throws Exception {
      NodeGroupEntity group=NodeGroupEntity.findNodeGroupEntityByName(cluster,nodeGroupName);
      if (group == null) {
        logger.error("String_Node_Str" + nodeGroupName + "String_Node_Str"+ clusterName+ "String_Node_Str");
        throw ClusterManagerException.NOGEGROUP_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());
      }
      group.validateHostNumber(instanceNum);
      group.validateIfHostCanSatisfied(instanceNum);
      return group;
    }
  }
);
  final int oldInstanceNum=group.getDefineInstanceNum();
  group.setDefineInstanceNum(instanceNum);
  DAL.inTransactionUpdate(group);
  UpdateClusterListener listener=new UpdateClusterListener(clusterName);
  try {
    return createClusterMgmtTask(cluster,listener,ClusterStatus.UPDATING);
  }
 catch (  Exception ex) {
    DAL.inTransactionDo(new Saveable<Void>(){
      @Override public Void body(){
        NodeGroupEntity group=NodeGroupEntity.findNodeGroupEntityByName(cluster,nodeGroupName);
        if (group == null) {
          logger.error("String_Node_Str" + nodeGroupName + "String_Node_Str"+ clusterName+ "String_Node_Str");
          throw ClusterManagerException.NOGEGROUP_NOT_FOUND_ERROR(nodeGroupName);
        }
        group.setDefineInstanceNum(oldInstanceNum);
        Set<HadoopNodeEntity> toRemove=new HashSet<HadoopNodeEntity>();
        if (group.getHadoopNodes() != null) {
          for (          HadoopNodeEntity node : group.getHadoopNodes()) {
            if (ClusterCmdUtil.getIndexFromNodeName(node.getVmName()) >= oldInstanceNum) {
              logger.info("String_Node_Str" + node.getVmName());
              toRemove.add(node);
              DAL.delete(node);
            }
          }
          group.getHadoopNodes().removeAll(toRemove);
        }
        return null;
      }
    }
);
    throw ex;
  }
}