Program: 49160
Project: 49160
Buggy source:
/** 
 * Validate nodeGroupCreates member formats and values in the ClusterCreate.
 */
private boolean validateClusterCreate(ClusterCreate clusterCreate){
  boolean validated=true;
  boolean warning=false;
  int masterCount=0, workerCount=0, clientCount=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> 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 (nodeGroupCreates.length < 2 || nodeGroupCreates.length > 4) {
      warning=true;
    }
    if (clusterCreate.hasHDFSUrlConfigured() && !clusterCreate.validateHDFSUrl()) {
      failedMsgList.add(new StringBuilder().append("String_Node_Str").append(clusterCreate.getExternalHDFS()).toString());
      validated=false;
    }
    if (!clusterCreate.validateNodeGroupPlacementPolicies(failedMsgList)) {
      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 WORKER:
  workerCount++;
if (nodeGroupCreate.getInstanceNum() == 0) {
  validated=false;
  collectInstanceNumInvalidateMsg(nodeGroupCreate,failedMsgList);
}
 else if (isHAFlag(nodeGroupCreate)) {
  warning=true;
}
break;
case CLIENT:
clientCount++;
if (nodeGroupCreate.getInstanceNum() == 0 || isHAFlag(nodeGroupCreate)) {
warning=true;
}
break;
case NONE:
warning=true;
break;
default :
}
}
if ((masterCount < 1 || masterCount > 2) || (workerCount < 1 || workerCount > 2) || clientCount > 1) {
warning=true;
}
if (!validated) {
showFailedMsg(clusterCreate.getName(),failedMsgList);
}
 else if (warning) {
showWarningMsg();
if (!isContinue(clusterCreate.getName(),Constants.OUTPUT_OP_CREATE,Constants.PARAM_PROMPT_CONTINUE_MESSAGE)) {
validated=false;
}
}
return validated;
}
}

Fixed version (ground truth):
/** 
 * Validate nodeGroupCreates member formats and values in the ClusterCreate.
 */
private boolean validateClusterCreate(ClusterCreate clusterCreate){
  boolean validated=true;
  boolean warning=false;
  int masterCount=0, workerCount=0, clientCount=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> 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 (nodeGroupCreates.length < 2 || nodeGroupCreates.length > 5) {
      warning=true;
    }
    if (clusterCreate.hasHDFSUrlConfigured() && !clusterCreate.validateHDFSUrl()) {
      failedMsgList.add(new StringBuilder().append("String_Node_Str").append(clusterCreate.getExternalHDFS()).toString());
      validated=false;
    }
    if (!clusterCreate.validateNodeGroupPlacementPolicies(failedMsgList)) {
      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 WORKER:
  workerCount++;
if (nodeGroupCreate.getInstanceNum() == 0) {
  validated=false;
  collectInstanceNumInvalidateMsg(nodeGroupCreate,failedMsgList);
}
 else if (isHAFlag(nodeGroupCreate)) {
  warning=true;
}
break;
case CLIENT:
clientCount++;
if (isHAFlag(nodeGroupCreate)) {
warning=true;
}
break;
case NONE:
warning=true;
break;
default :
}
}
if ((masterCount < 1 || masterCount > 2) || (workerCount < 1 || workerCount > 2) || clientCount > 1) {
warning=true;
}
if (!validated) {
showFailedMsg(clusterCreate.getName(),failedMsgList);
}
 else if (warning) {
showWarningMsg();
if (!isContinue(clusterCreate.getName(),Constants.OUTPUT_OP_CREATE,Constants.PARAM_PROMPT_CONTINUE_MESSAGE)) {
validated=false;
}
}
return validated;
}
}