Program: 14070
Project: 14070
Buggy source:
public CreateStackResponseType createStack(final CreateStackType request) throws CloudFormationException {
  CreateStackResponseType reply=request.getReply();
  try {
    final Context ctx=Contexts.lookup();
    final User user=ctx.getUser();
    final String userId=user.getUserId();
    final String accountId=ctx.getAccountNumber();
    final String accountAlias=ctx.getAccountAlias();
    final String stackName=request.getStackName();
    final String templateBody=request.getTemplateBody();
    final String templateUrl=request.getTemplateURL();
    final String stackPolicyBody=request.getStackPolicyBody();
    final String stackPolicyUrl=request.getStackPolicyURL();
    final String stackPolicyText=validateAndGetStackPolicy(user,stackPolicyBody,stackPolicyUrl);
    if (stackName == null)     throw new ValidationErrorException("String_Node_Str");
    if (!stackName.matches("String_Node_Str")) {
      throw new ValidationErrorException("String_Node_Str" + stackName + "String_Node_Str");
    }
    if (stackName.length() > Limits.STACK_NAME_MAX_LENGTH_CHARS) {
      throw new ValidationErrorException("String_Node_Str" + stackName + "String_Node_Str"+ Limits.STACK_NAME_MAX_LENGTH_CHARS+ "String_Node_Str");
    }
    if (templateBody == null && templateUrl == null)     throw new ValidationErrorException("String_Node_Str");
    if (templateBody != null && templateUrl != null)     throw new ValidationErrorException("String_Node_Str");
    List<Parameter> parameters=null;
    if (request.getParameters() != null && request.getParameters().getMember() != null) {
      parameters=request.getParameters().getMember();
    }
    final String stackIdLocal=UUID.randomUUID().toString();
    final String stackId=STACK_ID_PREFIX + REGION + "String_Node_Str"+ accountId+ "String_Node_Str"+ stackName+ "String_Node_Str"+ stackIdLocal;
    final PseudoParameterValues pseudoParameterValues=new PseudoParameterValues();
    pseudoParameterValues.setAccountId(accountId);
    pseudoParameterValues.setStackName(stackName);
    pseudoParameterValues.setStackId(stackId);
    if (request.getNotificationARNs() != null && request.getNotificationARNs().getMember() != null) {
      ArrayList<String> notificationArns=Lists.newArrayList();
      for (      String notificationArn : request.getNotificationARNs().getMember()) {
        notificationArns.add(notificationArn);
      }
      pseudoParameterValues.setNotificationArns(notificationArns);
    }
    pseudoParameterValues.setRegion(getRegion());
    final ArrayList<String> capabilities=Lists.newArrayList();
    if (request.getCapabilities() != null && request.getCapabilities().getMember() != null) {
      capabilities.addAll(request.getCapabilities().getMember());
    }
    if (templateBody != null) {
      if (templateBody.getBytes().length > Limits.REQUEST_TEMPLATE_BODY_MAX_LENGTH_BYTES) {
        throw new ValidationErrorException("String_Node_Str" + Limits.REQUEST_TEMPLATE_BODY_MAX_LENGTH_BYTES + "String_Node_Str");
      }
    }
    if (request.getTags() != null && request.getTags().getMember() != null) {
      for (      Tag tag : request.getTags().getMember()) {
        if (Strings.isNullOrEmpty(tag.getKey()) || Strings.isNullOrEmpty(tag.getValue())) {
          throw new ValidationErrorException("String_Node_Str");
        }
 else         if (tag.getKey().startsWith("String_Node_Str")) {
          throw new ValidationErrorException("String_Node_Str");
        }
 else         if (tag.getKey().startsWith("String_Node_Str")) {
          throw new ValidationErrorException("String_Node_Str");
        }
      }
    }
    final String templateText=(templateBody != null) ? templateBody : extractTemplateTextFromURL(templateUrl,user);
    final Template template=new TemplateParser().parse(templateText,parameters,capabilities,pseudoParameterValues,userId);
    final Supplier<StackEntity> allocator=new Supplier<StackEntity>(){
      @Override public StackEntity get(){
        try {
          StackEntity stackEntity=new StackEntity();
          final int INIT_STACK_VERSION=0;
          StackEntityHelper.populateStackEntityWithTemplate(stackEntity,template);
          stackEntity.setStackName(stackName);
          stackEntity.setStackId(stackId);
          stackEntity.setAccountId(accountId);
          stackEntity.setTemplateBody(templateText);
          stackEntity.setStackPolicy(stackPolicyText);
          stackEntity.setStackStatus(Status.CREATE_IN_PROGRESS);
          stackEntity.setStackStatusReason("String_Node_Str");
          stackEntity.setDisableRollback(request.getDisableRollback() == Boolean.TRUE);
          stackEntity.setCreationTimestamp(new Date());
          if (request.getCapabilities() != null && request.getCapabilities().getMember() != null) {
            stackEntity.setCapabilitiesJson(StackEntityHelper.capabilitiesToJson(capabilities));
          }
          if (request.getNotificationARNs() != null && request.getNotificationARNs().getMember() != null) {
            stackEntity.setNotificationARNsJson(StackEntityHelper.notificationARNsToJson(request.getNotificationARNs().getMember()));
          }
          if (request.getTags() != null && request.getTags().getMember() != null) {
            stackEntity.setTagsJson(StackEntityHelper.tagsToJson(request.getTags().getMember()));
          }
          stackEntity.setStackVersion(INIT_STACK_VERSION);
          stackEntity.setRecordDeleted(Boolean.FALSE);
          stackEntity=(StackEntity)StackEntityManager.addStack(stackEntity);
          String onFailure;
          if (request.getOnFailure() != null && !request.getOnFailure().isEmpty()) {
            if (!request.getOnFailure().equals("String_Node_Str") && !request.getOnFailure().equals("String_Node_Str") && !request.getOnFailure().equals("String_Node_Str")) {
              throw new ValidationErrorException("String_Node_Str" + request.getOnFailure() + "String_Node_Str"+ "String_Node_Str");
            }
 else {
              onFailure=request.getOnFailure();
            }
          }
 else {
            onFailure=(request.getDisableRollback() == Boolean.TRUE) ? "String_Node_Str" : "String_Node_Str";
          }
          for (          ResourceInfo resourceInfo : template.getResourceInfoMap().values()) {
            StackResourceEntity stackResourceEntity=new StackResourceEntity();
            stackResourceEntity=StackResourceEntityManager.updateResourceInfo(stackResourceEntity,resourceInfo);
            stackResourceEntity.setDescription("String_Node_Str");
            stackResourceEntity.setResourceStatus(Status.NOT_STARTED);
            stackResourceEntity.setStackId(stackId);
            stackResourceEntity.setStackName(stackName);
            stackResourceEntity.setResourceVersion(INIT_STACK_VERSION);
            stackResourceEntity.setRecordDeleted(Boolean.FALSE);
            StackResourceEntityManager.addStackResource(stackResourceEntity);
          }
          StackWorkflowTags stackWorkflowTags=new StackWorkflowTags(stackId,stackName,accountId,accountAlias);
          Long timeoutInSeconds=(request.getTimeoutInMinutes() != null && request.getTimeoutInMinutes() > 0 ? 60L * request.getTimeoutInMinutes() : null);
          StartTimeoutPassableWorkflowClientFactory createStackWorkflowClientFactory=new StartTimeoutPassableWorkflowClientFactory(WorkflowClientManager.getSimpleWorkflowClient(),CloudFormationProperties.SWF_DOMAIN,CloudFormationProperties.SWF_TASKLIST);
          WorkflowDescriptionTemplate createStackWorkflowDescriptionTemplate=new CreateStackWorkflowDescriptionTemplate();
          InterfaceBasedWorkflowClient<CreateStackWorkflow> createStackWorkflowClient=createStackWorkflowClientFactory.getNewWorkflowClient(CreateStackWorkflow.class,createStackWorkflowDescriptionTemplate,stackWorkflowTags,timeoutInSeconds,null);
          CreateStackWorkflow createStackWorkflow=new CreateStackWorkflowClient(createStackWorkflowClient);
          createStackWorkflow.createStack(stackEntity.getStackId(),stackEntity.getAccountId(),stackEntity.getResourceDependencyManagerJson(),userId,onFailure,INIT_STACK_VERSION);
          StackWorkflowEntityManager.addOrUpdateStackWorkflowEntity(stackId,StackWorkflowEntity.WorkflowType.CREATE_STACK_WORKFLOW,CloudFormationProperties.SWF_DOMAIN,createStackWorkflowClient.getWorkflowExecution().getWorkflowId(),createStackWorkflowClient.getWorkflowExecution().getRunId());
          WorkflowClientFactory monitorCreateStackWorkflowClientFactory=new WorkflowClientFactory(WorkflowClientManager.getSimpleWorkflowClient(),CloudFormationProperties.SWF_DOMAIN,CloudFormationProperties.SWF_TASKLIST);
          WorkflowDescriptionTemplate monitorCreateStackWorkflowDescriptionTemplate=new MonitorCreateStackWorkflowDescriptionTemplate();
          InterfaceBasedWorkflowClient<MonitorCreateStackWorkflow> monitorCreateStackWorkflowClient=monitorCreateStackWorkflowClientFactory.getNewWorkflowClient(MonitorCreateStackWorkflow.class,monitorCreateStackWorkflowDescriptionTemplate,stackWorkflowTags);
          MonitorCreateStackWorkflow monitorCreateStackWorkflow=new MonitorCreateStackWorkflowClient(monitorCreateStackWorkflowClient);
          monitorCreateStackWorkflow.monitorCreateStack(stackEntity.getStackId(),stackEntity.getAccountId(),stackEntity.getResourceDependencyManagerJson(),userId,onFailure,INIT_STACK_VERSION);
          StackWorkflowEntityManager.addOrUpdateStackWorkflowEntity(stackId,StackWorkflowEntity.WorkflowType.MONITOR_CREATE_STACK_WORKFLOW,CloudFormationProperties.SWF_DOMAIN,monitorCreateStackWorkflowClient.getWorkflowExecution().getWorkflowId(),monitorCreateStackWorkflowClient.getWorkflowExecution().getRunId());
          return stackEntity;
        }
 catch (        CloudFormationException e) {
          throw Exceptions.toUndeclared(e);
        }
      }
    }
;
    final StackEntity stackEntity=RestrictedTypes.allocateUnitlessResource(allocator);
    CreateStackResult createStackResult=new CreateStackResult();
    createStackResult.setStackId(stackId);
    reply.setCreateStackResult(createStackResult);
  }
 catch (  Exception ex) {
    handleException(ex);
  }
  return reply;
}

Fixed version (ground truth):
public CreateStackResponseType createStack(final CreateStackType request) throws CloudFormationException {
  CreateStackResponseType reply=request.getReply();
  try {
    final Context ctx=Contexts.lookup();
    final User user=ctx.getUser();
    final String userId=user.getUserId();
    final String accountId=ctx.getAccountNumber();
    final String accountAlias=ctx.getAccountAlias();
    final String stackName=request.getStackName();
    final String templateBody=request.getTemplateBody();
    final String templateUrl=request.getTemplateURL();
    final String stackPolicyBody=request.getStackPolicyBody();
    final String stackPolicyUrl=request.getStackPolicyURL();
    final String stackPolicyText=validateAndGetStackPolicy(user,stackPolicyBody,stackPolicyUrl);
    if (stackName == null)     throw new ValidationErrorException("String_Node_Str");
    if (!stackName.matches("String_Node_Str")) {
      throw new ValidationErrorException("String_Node_Str" + stackName + "String_Node_Str");
    }
    if (stackName.length() > Limits.STACK_NAME_MAX_LENGTH_CHARS) {
      throw new ValidationErrorException("String_Node_Str" + stackName + "String_Node_Str"+ Limits.STACK_NAME_MAX_LENGTH_CHARS+ "String_Node_Str");
    }
    if (templateBody == null && templateUrl == null)     throw new ValidationErrorException("String_Node_Str");
    if (templateBody != null && templateUrl != null)     throw new ValidationErrorException("String_Node_Str");
    List<Parameter> parameters=null;
    if (request.getParameters() != null && request.getParameters().getMember() != null) {
      parameters=request.getParameters().getMember();
    }
    final String stackIdLocal=UUID.randomUUID().toString();
    final String stackId=STACK_ID_PREFIX + REGION + "String_Node_Str"+ accountId+ "String_Node_Str"+ stackName+ "String_Node_Str"+ stackIdLocal;
    final PseudoParameterValues pseudoParameterValues=new PseudoParameterValues();
    pseudoParameterValues.setAccountId(accountId);
    pseudoParameterValues.setStackName(stackName);
    pseudoParameterValues.setStackId(stackId);
    if (request.getNotificationARNs() != null && request.getNotificationARNs().getMember() != null) {
      ArrayList<String> notificationArns=Lists.newArrayList();
      for (      String notificationArn : request.getNotificationARNs().getMember()) {
        notificationArns.add(notificationArn);
      }
      pseudoParameterValues.setNotificationArns(notificationArns);
    }
    pseudoParameterValues.setRegion(getRegion());
    final ArrayList<String> capabilities=Lists.newArrayList();
    if (request.getCapabilities() != null && request.getCapabilities().getMember() != null) {
      capabilities.addAll(request.getCapabilities().getMember());
    }
    if (templateBody != null) {
      if (templateBody.getBytes().length > Limits.REQUEST_TEMPLATE_BODY_MAX_LENGTH_BYTES) {
        throw new ValidationErrorException("String_Node_Str" + Limits.REQUEST_TEMPLATE_BODY_MAX_LENGTH_BYTES + "String_Node_Str");
      }
    }
    if (request.getTags() != null && request.getTags().getMember() != null) {
      for (      Tag tag : request.getTags().getMember()) {
        if (Strings.isNullOrEmpty(tag.getKey()) || Strings.isNullOrEmpty(tag.getValue())) {
          throw new ValidationErrorException("String_Node_Str");
        }
 else         if (tag.getKey().startsWith("String_Node_Str")) {
          throw new ValidationErrorException("String_Node_Str");
        }
 else         if (tag.getKey().startsWith("String_Node_Str")) {
          throw new ValidationErrorException("String_Node_Str");
        }
      }
    }
    final String templateText=(templateBody != null) ? templateBody : extractTemplateTextFromURL(templateUrl,user);
    final Template template=new TemplateParser().parse(templateText,parameters,capabilities,pseudoParameterValues,userId);
    final Supplier<StackEntity> allocator=new Supplier<StackEntity>(){
      @Override public StackEntity get(){
        try {
          StackEntity stackEntity=new StackEntity();
          final int INIT_STACK_VERSION=0;
          StackEntityHelper.populateStackEntityWithTemplate(stackEntity,template);
          stackEntity.setStackName(stackName);
          stackEntity.setStackId(stackId);
          stackEntity.setAccountId(accountId);
          stackEntity.setTemplateBody(templateText);
          stackEntity.setStackPolicy(stackPolicyText);
          stackEntity.setStackStatus(Status.CREATE_IN_PROGRESS);
          stackEntity.setStackStatusReason("String_Node_Str");
          stackEntity.setDisableRollback(Boolean.TRUE.equals(request.getDisableRollback()));
          stackEntity.setCreationTimestamp(new Date());
          if (request.getCapabilities() != null && request.getCapabilities().getMember() != null) {
            stackEntity.setCapabilitiesJson(StackEntityHelper.capabilitiesToJson(capabilities));
          }
          if (request.getNotificationARNs() != null && request.getNotificationARNs().getMember() != null) {
            stackEntity.setNotificationARNsJson(StackEntityHelper.notificationARNsToJson(request.getNotificationARNs().getMember()));
          }
          if (request.getTags() != null && request.getTags().getMember() != null) {
            stackEntity.setTagsJson(StackEntityHelper.tagsToJson(request.getTags().getMember()));
          }
          stackEntity.setStackVersion(INIT_STACK_VERSION);
          stackEntity.setRecordDeleted(Boolean.FALSE);
          stackEntity=(StackEntity)StackEntityManager.addStack(stackEntity);
          String onFailure;
          if (request.getOnFailure() != null && !request.getOnFailure().isEmpty()) {
            if (!request.getOnFailure().equals("String_Node_Str") && !request.getOnFailure().equals("String_Node_Str") && !request.getOnFailure().equals("String_Node_Str")) {
              throw new ValidationErrorException("String_Node_Str" + request.getOnFailure() + "String_Node_Str"+ "String_Node_Str");
            }
 else {
              onFailure=request.getOnFailure();
            }
          }
 else {
            onFailure=(Boolean.TRUE.equals(request.getDisableRollback())) ? "String_Node_Str" : "String_Node_Str";
          }
          for (          ResourceInfo resourceInfo : template.getResourceInfoMap().values()) {
            StackResourceEntity stackResourceEntity=new StackResourceEntity();
            stackResourceEntity=StackResourceEntityManager.updateResourceInfo(stackResourceEntity,resourceInfo);
            stackResourceEntity.setDescription("String_Node_Str");
            stackResourceEntity.setResourceStatus(Status.NOT_STARTED);
            stackResourceEntity.setStackId(stackId);
            stackResourceEntity.setStackName(stackName);
            stackResourceEntity.setResourceVersion(INIT_STACK_VERSION);
            stackResourceEntity.setRecordDeleted(Boolean.FALSE);
            StackResourceEntityManager.addStackResource(stackResourceEntity);
          }
          StackWorkflowTags stackWorkflowTags=new StackWorkflowTags(stackId,stackName,accountId,accountAlias);
          Long timeoutInSeconds=(request.getTimeoutInMinutes() != null && request.getTimeoutInMinutes() > 0 ? 60L * request.getTimeoutInMinutes() : null);
          StartTimeoutPassableWorkflowClientFactory createStackWorkflowClientFactory=new StartTimeoutPassableWorkflowClientFactory(WorkflowClientManager.getSimpleWorkflowClient(),CloudFormationProperties.SWF_DOMAIN,CloudFormationProperties.SWF_TASKLIST);
          WorkflowDescriptionTemplate createStackWorkflowDescriptionTemplate=new CreateStackWorkflowDescriptionTemplate();
          InterfaceBasedWorkflowClient<CreateStackWorkflow> createStackWorkflowClient=createStackWorkflowClientFactory.getNewWorkflowClient(CreateStackWorkflow.class,createStackWorkflowDescriptionTemplate,stackWorkflowTags,timeoutInSeconds,null);
          CreateStackWorkflow createStackWorkflow=new CreateStackWorkflowClient(createStackWorkflowClient);
          createStackWorkflow.createStack(stackEntity.getStackId(),stackEntity.getAccountId(),stackEntity.getResourceDependencyManagerJson(),userId,onFailure,INIT_STACK_VERSION);
          StackWorkflowEntityManager.addOrUpdateStackWorkflowEntity(stackId,StackWorkflowEntity.WorkflowType.CREATE_STACK_WORKFLOW,CloudFormationProperties.SWF_DOMAIN,createStackWorkflowClient.getWorkflowExecution().getWorkflowId(),createStackWorkflowClient.getWorkflowExecution().getRunId());
          WorkflowClientFactory monitorCreateStackWorkflowClientFactory=new WorkflowClientFactory(WorkflowClientManager.getSimpleWorkflowClient(),CloudFormationProperties.SWF_DOMAIN,CloudFormationProperties.SWF_TASKLIST);
          WorkflowDescriptionTemplate monitorCreateStackWorkflowDescriptionTemplate=new MonitorCreateStackWorkflowDescriptionTemplate();
          InterfaceBasedWorkflowClient<MonitorCreateStackWorkflow> monitorCreateStackWorkflowClient=monitorCreateStackWorkflowClientFactory.getNewWorkflowClient(MonitorCreateStackWorkflow.class,monitorCreateStackWorkflowDescriptionTemplate,stackWorkflowTags);
          MonitorCreateStackWorkflow monitorCreateStackWorkflow=new MonitorCreateStackWorkflowClient(monitorCreateStackWorkflowClient);
          monitorCreateStackWorkflow.monitorCreateStack(stackEntity.getStackId(),stackEntity.getAccountId(),stackEntity.getResourceDependencyManagerJson(),userId,onFailure,INIT_STACK_VERSION);
          StackWorkflowEntityManager.addOrUpdateStackWorkflowEntity(stackId,StackWorkflowEntity.WorkflowType.MONITOR_CREATE_STACK_WORKFLOW,CloudFormationProperties.SWF_DOMAIN,monitorCreateStackWorkflowClient.getWorkflowExecution().getWorkflowId(),monitorCreateStackWorkflowClient.getWorkflowExecution().getRunId());
          return stackEntity;
        }
 catch (        CloudFormationException e) {
          throw Exceptions.toUndeclared(e);
        }
      }
    }
;
    final StackEntity stackEntity=RestrictedTypes.allocateUnitlessResource(allocator);
    CreateStackResult createStackResult=new CreateStackResult();
    createStackResult.setStackId(stackId);
    reply.setCreateStackResult(createStackResult);
  }
 catch (  Exception ex) {
    handleException(ex);
  }
  return reply;
}