Program: 49073
Project: 49073
Buggy source:
/** 
 * Validate nodeGroupCreates member formats and values in the ClusterCreate.
 */
private boolean validateClusterCreate(ClusterCreate clusterCreate,final boolean alwaysAnswerYes){
  boolean validated=true;
  boolean warning=false;
  int masterCount=0, jobtrackerCount=0, hbasemasterCount=0, zookeeperCount=0, workerCount=0;
  NodeGroupCreate[] nodeGroupCreates=clusterCreate.getNodeGroups();
  if (nodeGroupCreates == null || nodeGroupCreates.length == 0) {
    CommandsUtils.printCmdFailure(Constants.OUTPUT_OBJECT_CLUSTER,clusterCreate.getName(),Constants.OUTPUT_OP_CREATE,Constants.OUTPUT_OP_RESULT_FAIL,Constants.MULTI_INPUTS_CHECK);
    return !validated;
  }
 else {
    List<String> failedMsgList=new LinkedList<String>();
    List<String> warningMsgList=new LinkedList<String>();
    List<String> distroRoles=findDistroRoles(clusterCreate);
    if (distroRoles == null) {
      CommandsUtils.printCmdFailure(Constants.OUTPUT_OBJECT_CLUSTER,clusterCreate.getName(),Constants.OUTPUT_OP_CREATE,Constants.OUTPUT_OP_RESULT_FAIL,Constants.PARAM_NO_DISTRO_AVAILABLE);
      return !validated;
    }
    if (clusterCreate.hasHDFSUrlConfigured() && !clusterCreate.validateHDFSUrl()) {
      failedMsgList.add(new StringBuilder().append("String_Node_Str").append(clusterCreate.getExternalHDFS()).toString());
      validated=false;
    }
    if (!clusterCreate.validateNodeGroupPlacementPolicies(failedMsgList,warningMsgList)) {
      validated=false;
    }
    if (!clusterCreate.validateNodeGroupRoles(failedMsgList)) {
      validated=false;
    }
    for (    NodeGroupCreate nodeGroupCreate : nodeGroupCreates) {
      if (!checkInstanceNum(nodeGroupCreate,failedMsgList)) {
        validated=false;
      }
      if (!checkNodeGroupRoles(nodeGroupCreate,distroRoles,failedMsgList)) {
        validated=false;
      }
      NodeGroupRole role=getNodeGroupRole(nodeGroupCreate);
switch (role) {
case MASTER:
        masterCount++;
      if (nodeGroupCreate.getInstanceNum() >= 0 && nodeGroupCreate.getInstanceNum() != 1) {
        validated=false;
        collectInstanceNumInvalidateMsg(nodeGroupCreate,failedMsgList);
      }
    break;
case JOB_TRACKER:
  jobtrackerCount++;
if (nodeGroupCreate.getInstanceNum() >= 0 && nodeGroupCreate.getInstanceNum() != 1) {
  validated=false;
  collectInstanceNumInvalidateMsg(nodeGroupCreate,failedMsgList);
}
break;
case HBASE_MASTER:
hbasemasterCount++;
if (nodeGroupCreate.getInstanceNum() == 0) {
validated=false;
collectInstanceNumInvalidateMsg(nodeGroupCreate,failedMsgList);
}
break;
case ZOOKEEPER:
zookeeperCount++;
if (nodeGroupCreate.getInstanceNum() > 0 && nodeGroupCreate.getInstanceNum() < 3) {
validated=false;
failedMsgList.add(Constants.WRONG_NUM_OF_ZOOKEEPER);
}
 else if (nodeGroupCreate.getInstanceNum() > 0 && nodeGroupCreate.getInstanceNum() % 2 == 0) {
warningMsgList.add(Constants.ODD_NUM_OF_ZOOKEEPER);
warning=true;
}
break;
case WORKER:
workerCount++;
if (nodeGroupCreate.getInstanceNum() == 0) {
validated=false;
collectInstanceNumInvalidateMsg(nodeGroupCreate,failedMsgList);
}
 else if (isHAFlag(nodeGroupCreate)) {
warning=true;
}
List<String> roles=nodeGroupCreate.getRoles();
if (roles.contains(HadoopRole.HBASE_REGIONSERVER_ROLE.toString()) && !roles.contains(HadoopRole.HADOOP_DATANODE.toString())) {
warningMsgList.add(Constants.REGISONSERVER_DATANODE_SEPERATION);
warning=true;
}
break;
case CLIENT:
if (isHAFlag(nodeGroupCreate)) {
warning=true;
}
break;
case NONE:
warning=true;
break;
default :
}
}
if ((masterCount > 1) || (jobtrackerCount > 1) || (zookeeperCount > 1)|| (hbasemasterCount > 1)|| (workerCount == 0)) {
warningMsgList.add(Constants.WRONG_NUM_OF_NODES);
warning=true;
}
if (!validated) {
showFailedMsg(clusterCreate.getName(),failedMsgList);
}
 else if (warning || warningMsgList != null) {
if (!CommandsUtils.showWarningMsg(clusterCreate.getName(),Constants.OUTPUT_OBJECT_CLUSTER,Constants.OUTPUT_OP_CREATE,warningMsgList,alwaysAnswerYes)) {
validated=false;
}
}
return validated;
}
}

Fixed version (ground truth):
/** 
 * Validate nodeGroupCreates member formats and values in the ClusterCreate.
 */
private boolean validateClusterCreate(ClusterCreate clusterCreate,final boolean alwaysAnswerYes){
  boolean validated=true;
  boolean warning=false;
  int masterCount=0, jobtrackerCount=0, hbasemasterCount=0, zookeeperCount=0, workerCount=0;
  NodeGroupCreate[] nodeGroupCreates=clusterCreate.getNodeGroups();
  if (nodeGroupCreates == null || nodeGroupCreates.length == 0) {
    CommandsUtils.printCmdFailure(Constants.OUTPUT_OBJECT_CLUSTER,clusterCreate.getName(),Constants.OUTPUT_OP_CREATE,Constants.OUTPUT_OP_RESULT_FAIL,Constants.MULTI_INPUTS_CHECK);
    return !validated;
  }
 else {
    List<String> failedMsgList=new LinkedList<String>();
    List<String> warningMsgList=new LinkedList<String>();
    List<String> distroRoles=findDistroRoles(clusterCreate);
    if (distroRoles == null) {
      CommandsUtils.printCmdFailure(Constants.OUTPUT_OBJECT_CLUSTER,clusterCreate.getName(),Constants.OUTPUT_OP_CREATE,Constants.OUTPUT_OP_RESULT_FAIL,Constants.PARAM_NO_DISTRO_AVAILABLE);
      return !validated;
    }
    if (clusterCreate.hasHDFSUrlConfigured() && !clusterCreate.validateHDFSUrl()) {
      failedMsgList.add(new StringBuilder().append("String_Node_Str").append(clusterCreate.getExternalHDFS()).toString());
      validated=false;
    }
    if (!clusterCreate.validateNodeGroupPlacementPolicies(failedMsgList,warningMsgList)) {
      validated=false;
    }
    if (!clusterCreate.validateNodeGroupRoles(failedMsgList)) {
      validated=false;
    }
    for (    NodeGroupCreate nodeGroupCreate : nodeGroupCreates) {
      if (!checkInstanceNum(nodeGroupCreate,failedMsgList)) {
        validated=false;
      }
      if (!checkNodeGroupRoles(nodeGroupCreate,distroRoles,failedMsgList)) {
        validated=false;
      }
      NodeGroupRole role=getNodeGroupRole(nodeGroupCreate);
switch (role) {
case MASTER:
        masterCount++;
      if (nodeGroupCreate.getInstanceNum() >= 0 && nodeGroupCreate.getInstanceNum() != 1) {
        validated=false;
        collectInstanceNumInvalidateMsg(nodeGroupCreate,failedMsgList);
      }
    break;
case JOB_TRACKER:
  jobtrackerCount++;
if (nodeGroupCreate.getInstanceNum() >= 0 && nodeGroupCreate.getInstanceNum() != 1) {
  validated=false;
  collectInstanceNumInvalidateMsg(nodeGroupCreate,failedMsgList);
}
break;
case HBASE_MASTER:
hbasemasterCount++;
if (nodeGroupCreate.getInstanceNum() == 0) {
validated=false;
collectInstanceNumInvalidateMsg(nodeGroupCreate,failedMsgList);
}
break;
case ZOOKEEPER:
zookeeperCount++;
if (nodeGroupCreate.getInstanceNum() > 0 && nodeGroupCreate.getInstanceNum() < 3) {
validated=false;
failedMsgList.add(Constants.WRONG_NUM_OF_ZOOKEEPER);
}
 else if (nodeGroupCreate.getInstanceNum() > 0 && nodeGroupCreate.getInstanceNum() % 2 == 0) {
warningMsgList.add(Constants.ODD_NUM_OF_ZOOKEEPER);
warning=true;
}
break;
case WORKER:
workerCount++;
if (nodeGroupCreate.getInstanceNum() == 0) {
validated=false;
collectInstanceNumInvalidateMsg(nodeGroupCreate,failedMsgList);
}
 else if (isHAFlag(nodeGroupCreate)) {
warning=true;
}
List<String> roles=nodeGroupCreate.getRoles();
if (roles.contains(HadoopRole.HBASE_REGIONSERVER_ROLE.toString()) && !roles.contains(HadoopRole.HADOOP_DATANODE.toString())) {
warningMsgList.add(Constants.REGISONSERVER_DATANODE_SEPERATION);
warning=true;
}
break;
case CLIENT:
if (isHAFlag(nodeGroupCreate)) {
warning=true;
}
break;
case NONE:
warning=true;
break;
default :
}
}
if ((masterCount > 1) || (jobtrackerCount > 1) || (zookeeperCount > 1)|| (hbasemasterCount > 1)) {
failedMsgList.add(Constants.WRONG_NUM_OF_NODES);
validated=false;
}
if (workerCount == 0) {
warningMsgList.add(Constants.WRONG_NUM_OF_NODES);
warning=true;
}
if (!validated) {
showFailedMsg(clusterCreate.getName(),failedMsgList);
}
 else if (warning || warningMsgList != null) {
if (!CommandsUtils.showWarningMsg(clusterCreate.getName(),Constants.OUTPUT_OBJECT_CLUSTER,Constants.OUTPUT_OP_CREATE,warningMsgList,alwaysAnswerYes)) {
validated=false;
}
}
return validated;
}
}