Program: 29356
Project: 29356
Buggy source:
public void execute(AdminCommandContext context){
  Iterator it=matchedVersions.iterator();
  while (it.hasNext()) {
    String appName=(String)it.next();
    if (target == null) {
      target=deployment.getDefaultTarget(appName,origin,_classicstyle);
    }
    ApplicationInfo info=deployment.get(appName);
    Application application=apps.getModule(Application.class,appName);
    if (application == null) {
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",appName));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
    deployment.validateUndeploymentTarget(target,appName);
    if (!DeploymentUtils.isDomainTarget(target)) {
      ApplicationRef ref=domain.getApplicationRefInTarget(appName,target);
      if (ref == null) {
        report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",appName,target));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
      }
    }
    ReadableArchive source=null;
    if (info == null) {
      URI uri=null;
      try {
        uri=new URI(application.getLocation());
      }
 catch (      URISyntaxException e) {
        logger.severe("String_Node_Str" + e.getMessage());
      }
      if (uri != null) {
        File location=new File(uri);
        if (location.exists()) {
          try {
            source=archiveFactory.openArchive(location);
          }
 catch (          IOException e) {
            logger.log(Level.INFO,e.getMessage(),e);
          }
        }
 else {
          logger.warning("String_Node_Str" + location + "String_Node_Str");
        }
      }
    }
 else {
      source=info.getSource();
    }
    if (source == null) {
      logger.fine("String_Node_Str");
      try {
        deployment.unregisterAppFromDomainXML(appName,target);
      }
 catch (      TransactionFailure e) {
        logger.warning("String_Node_Str" + appName + "String_Node_Str");
      }
      return;
    }
    File sourceFile=new File(source.getURI());
    if (!source.exists()) {
      logger.log(Level.WARNING,"String_Node_Str" + sourceFile.getPath());
      try {
        deployment.unregisterAppFromDomainXML(appName,target);
      }
 catch (      TransactionFailure e) {
        logger.warning("String_Node_Str" + appName + "String_Node_Str");
      }
      return;
    }
    this.name=appName;
    ExtendedDeploymentContext deploymentContext=null;
    try {
      deploymentContext=deployment.getBuilder(logger,this,report).source(source).build();
    }
 catch (    IOException e) {
      logger.log(Level.SEVERE,"String_Node_Str",e);
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",e.getMessage()));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
    final InterceptorNotifier notifier=new InterceptorNotifier(habitat,deploymentContext);
    final DeployCommandSupplementalInfo suppInfo=new DeployCommandSupplementalInfo();
    suppInfo.setDeploymentContext(deploymentContext);
    report.setResultType(DeployCommandSupplementalInfo.class,suppInfo);
    final Properties appProps=deploymentContext.getAppProps();
    appProps.putAll(application.getDeployProperties());
    if (properties != null) {
      appProps.putAll(properties);
    }
    deploymentContext.setModulePropsMap(application.getModulePropertiesMap());
    events.send(new Event<DeploymentContext>(Deployment.UNDEPLOYMENT_VALIDATION,deploymentContext),false);
    if (report.getActionExitCode() == ActionReport.ExitCode.FAILURE) {
      return;
    }
    if (env.isDas() && !DeploymentUtils.isDASTarget(target)) {
      ActionReport subReport=report.addSubActionsReport();
      CommandRunner.CommandInvocation inv=commandRunner.getCommandInvocation("String_Node_Str",subReport);
      try {
        final ParameterMapExtractor extractor=new ParameterMapExtractor(this);
        final ParameterMap parameters=extractor.extract(Collections.EMPTY_LIST);
        parameters.set("String_Node_Str",appName);
        parameters.add(DeploymentProperties.IS_UNDEPLOY,Boolean.TRUE.toString());
        inv.parameters(parameters).execute();
        if (subReport.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
          report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",appName));
          return;
        }
        if (DeploymentUtils.isDomainTarget(target)) {
          List<String> targets=domain.getAllReferencedTargetsForApplication(appName);
          parameters.remove("String_Node_Str");
          notifier.ensureBeforeReported(ExtendedDeploymentContext.Phase.REPLICATION);
          ClusterOperationUtil.replicateCommand("String_Node_Str",FailurePolicy.Error,FailurePolicy.Warn,FailurePolicy.Ignore,targets,context,parameters,habitat);
        }
      }
 catch (      Exception e) {
        report.failure(logger,e.getMessage());
        return;
      }
    }
    final Artifacts generatedArtifacts=DeploymentUtils.generatedArtifacts(application);
    generatedArtifacts.record(deploymentContext);
    if (info != null) {
      deployment.undeploy(appName,deploymentContext);
    }
    boolean isDirectoryDeployed=false;
    if (application != null) {
      isDirectoryDeployed=Boolean.valueOf(application.getDirectoryDeployed());
    }
    if (!report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
      try {
        deployment.unregisterAppFromDomainXML(appName,target);
      }
 catch (      TransactionFailure e) {
        logger.warning("String_Node_Str" + appName + "String_Node_Str");
      }
      deploymentContext.clean();
      if ((!keepreposdir) && !isDirectoryDeployed && source.exists()) {
        source.delete();
      }
    }
  }
}

Fixed version (ground truth):
public void execute(AdminCommandContext context){
  Iterator it=matchedVersions.iterator();
  while (it.hasNext()) {
    String appName=(String)it.next();
    if (target == null) {
      target=deployment.getDefaultTarget(appName,origin,_classicstyle);
    }
    ApplicationInfo info=deployment.get(appName);
    Application application=apps.getModule(Application.class,appName);
    if (application == null) {
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",appName));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
    deployment.validateUndeploymentTarget(target,appName);
    if (!DeploymentUtils.isDomainTarget(target)) {
      ApplicationRef ref=domain.getApplicationRefInTarget(appName,target);
      if (ref == null) {
        report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",appName,target));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
      }
    }
    ReadableArchive source=null;
    if (info == null) {
      URI uri=null;
      try {
        uri=new URI(application.getLocation());
      }
 catch (      URISyntaxException e) {
        logger.severe("String_Node_Str" + e.getMessage());
      }
      if (uri != null) {
        File location=new File(uri);
        if (location.exists()) {
          try {
            source=archiveFactory.openArchive(location);
          }
 catch (          IOException e) {
            logger.log(Level.INFO,e.getMessage(),e);
          }
        }
 else {
          logger.warning("String_Node_Str" + location + "String_Node_Str");
        }
      }
    }
 else {
      source=info.getSource();
    }
    if (source == null) {
      logger.fine("String_Node_Str");
      try {
        deployment.unregisterAppFromDomainXML(appName,target);
      }
 catch (      TransactionFailure e) {
        logger.warning("String_Node_Str" + appName + "String_Node_Str");
      }
      return;
    }
    File sourceFile=new File(source.getURI());
    if (!source.exists()) {
      logger.log(Level.WARNING,"String_Node_Str" + sourceFile.getPath());
      try {
        deployment.unregisterAppFromDomainXML(appName,target);
      }
 catch (      TransactionFailure e) {
        logger.warning("String_Node_Str" + appName + "String_Node_Str");
      }
      return;
    }
    this.name=appName;
    ExtendedDeploymentContext deploymentContext=null;
    try {
      deploymentContext=deployment.getBuilder(logger,this,report).source(source).build();
    }
 catch (    IOException e) {
      logger.log(Level.SEVERE,"String_Node_Str",e);
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",e.getMessage()));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
    final InterceptorNotifier notifier=new InterceptorNotifier(habitat,deploymentContext);
    final DeployCommandSupplementalInfo suppInfo=new DeployCommandSupplementalInfo();
    suppInfo.setDeploymentContext(deploymentContext);
    report.setResultType(DeployCommandSupplementalInfo.class,suppInfo);
    final Properties appProps=deploymentContext.getAppProps();
    appProps.putAll(application.getDeployProperties());
    if (properties != null) {
      appProps.putAll(properties);
    }
    deploymentContext.setModulePropsMap(application.getModulePropertiesMap());
    events.send(new Event<DeploymentContext>(Deployment.UNDEPLOYMENT_VALIDATION,deploymentContext),false);
    if (report.getActionExitCode() == ActionReport.ExitCode.FAILURE) {
      return;
    }
    if (env.isDas() && !DeploymentUtils.isDASTarget(target)) {
      ActionReport subReport=report.addSubActionsReport();
      CommandRunner.CommandInvocation inv=commandRunner.getCommandInvocation("String_Node_Str",subReport);
      try {
        final ParameterMapExtractor extractor=new ParameterMapExtractor(this);
        final ParameterMap parameters=extractor.extract(Collections.EMPTY_LIST);
        parameters.set("String_Node_Str",appName);
        parameters.add(DeploymentProperties.IS_UNDEPLOY,Boolean.TRUE.toString());
        inv.parameters(parameters).execute();
        if (subReport.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
          report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",appName));
          return;
        }
        if (DeploymentUtils.isDomainTarget(target)) {
          List<String> targets=domain.getAllReferencedTargetsForApplication(appName);
          parameters.remove("String_Node_Str");
          notifier.ensureBeforeReported(ExtendedDeploymentContext.Phase.REPLICATION);
          ClusterOperationUtil.replicateCommand("String_Node_Str",FailurePolicy.Error,FailurePolicy.Warn,FailurePolicy.Ignore,targets,context,parameters,habitat);
        }
      }
 catch (      Exception e) {
        report.failure(logger,e.getMessage());
        return;
      }
    }
    final Artifacts generatedArtifacts=DeploymentUtils.generatedArtifacts(application);
    generatedArtifacts.record(deploymentContext);
    if (info != null) {
      deployment.undeploy(appName,deploymentContext);
    }
    boolean isDirectoryDeployed=Boolean.valueOf(application.getDirectoryDeployed());
    if (!report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
      try {
        deployment.unregisterAppFromDomainXML(appName,target);
      }
 catch (      TransactionFailure e) {
        logger.warning("String_Node_Str" + appName + "String_Node_Str");
      }
      deploymentContext.clean();
      if ((!keepreposdir) && !isDirectoryDeployed && source.exists()) {
        source.delete();
      }
    }
  }
}