Program: 29351
Project: 29351
Buggy source:
/** 
 * Entry point from the framework into the command execution
 * @param context context for the command.
 */
public void execute(AdminCommandContext context){
  final ActionReport report=context.getActionReport();
  final Logger logger=context.getLogger();
  List<String> matchedVersions=null;
  if (enabled) {
    try {
      VersioningUtils.checkIdentifier(name);
      matchedVersions=new ArrayList<String>(1);
      matchedVersions.add(name);
    }
 catch (    VersioningWildcardException ex) {
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str"));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
catch (    VersioningSyntaxException ex) {
      report.setMessage(ex.getLocalizedMessage());
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
    if (!deployment.isRegistered(name)) {
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",name));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
  }
 else {
    try {
      matchedVersions=versioningService.getMatchedVersions(name,null);
    }
 catch (    VersioningException e) {
      report.failure(logger,e.getMessage());
      return;
    }
    if (matchedVersions.isEmpty()) {
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",name,target));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
  }
  ActionReport.MessagePart part=report.getTopMessagePart();
  boolean isVersionExpression=VersioningUtils.isVersionExpression(name);
  Iterator it=matchedVersions.iterator();
  while (it.hasNext()) {
    String appName=(String)it.next();
    Application app=applications.getApplication(appName);
    ApplicationRef applicationRef=domain.getApplicationRefInTarget(appName,target);
    if (applicationRef != null) {
      if (isVersionExpression) {
        ActionReport.MessagePart childPart=part.addChild();
        childPart.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",appName,target));
      }
 else {
        report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",name,target));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
      }
    }
 else {
      Transaction t=new Transaction();
      if (app.isLifecycleModule()) {
        handleLifecycleModule(context,t);
        return;
      }
      ReadableArchive archive;
      File file=null;
      DeployCommandParameters commandParams=null;
      Properties contextProps=new Properties();
      Map<String,Properties> modulePropsMap=null;
      ApplicationConfigInfo savedAppConfig=null;
      try {
        commandParams=app.getDeployParameters(null);
        commandParams.origin=Origin.create_application_ref;
        commandParams.command=Command.create_application_ref;
        commandParams.target=target;
        commandParams.virtualservers=virtualservers;
        commandParams.enabled=enabled;
        if (lbenabled != null) {
          commandParams.lbenabled=lbenabled;
        }
        if (app.containsSnifferType(ServerTags.OSGI)) {
          commandParams.type=DeploymentProperties.OSGI;
        }
        contextProps=app.getDeployProperties();
        modulePropsMap=app.getModulePropertiesMap();
        savedAppConfig=new ApplicationConfigInfo(app);
        URI uri=new URI(app.getLocation());
        file=new File(uri);
        if (!file.exists()) {
          report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",file.getAbsolutePath()));
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          return;
        }
        archive=archiveFactory.openArchive(file);
      }
 catch (      Exception e) {
        logger.log(Level.SEVERE,"String_Node_Str" + file.getAbsolutePath(),e);
        report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
      }
      try {
        final ExtendedDeploymentContext deploymentContext=deployment.getBuilder(logger,commandParams,report).source(archive).build();
        Properties appProps=deploymentContext.getAppProps();
        appProps.putAll(contextProps);
        String location=DeploymentUtils.relativizeWithinDomainIfPossible(new URI(app.getLocation()));
        appProps.setProperty(ServerTags.LOCATION,location);
        String appLocation=appProps.getProperty(Application.APP_LOCATION_PROP_NAME);
        appProps.setProperty(Application.APP_LOCATION_PROP_NAME,DeploymentUtils.relativizeWithinDomainIfPossible(new URI(appLocation)));
        String planLocation=appProps.getProperty(Application.DEPLOYMENT_PLAN_LOCATION_PROP_NAME);
        if (planLocation != null) {
          appProps.setProperty(Application.DEPLOYMENT_PLAN_LOCATION_PROP_NAME,DeploymentUtils.relativizeWithinDomainIfPossible(new URI(planLocation)));
        }
        savedAppConfig.store(appProps);
        if (modulePropsMap != null) {
          deploymentContext.setModulePropsMap(modulePropsMap);
        }
        if (enabled) {
          versioningService.handleDisable(appName,target,deploymentContext.getActionReport());
        }
        if (domain.isCurrentInstanceMatchingTarget(target,appName,server.getName(),null)) {
          deployment.deploy(deployment.getSniffersFromApp(app),deploymentContext);
        }
 else {
          events.send(new Event<DeploymentContext>(Deployment.APPLICATION_PREPARED,deploymentContext),false);
        }
        if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
          try {
            deployment.registerAppInDomainXML(null,deploymentContext,t,true);
          }
 catch (          TransactionFailure e) {
            logger.warning("String_Node_Str" + appName);
          }
        }
        if (!isVersionExpression && DeploymentUtils.isDASTarget(target)) {
          return;
        }
        final ParameterMap paramMap=deployment.prepareInstanceDeployParamMap(deploymentContext);
        final List<String> targets=new ArrayList<String>(Arrays.asList(commandParams.target.split("String_Node_Str")));
        ClusterOperationUtil.replicateCommand("String_Node_Str",FailurePolicy.Error,FailurePolicy.Warn,FailurePolicy.Ignore,targets,context,paramMap,habitat);
      }
 catch (      Exception e) {
        logger.log(Level.SEVERE,"String_Node_Str",e);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      }
 finally {
        try {
          archive.close();
        }
 catch (        IOException e) {
          logger.log(Level.INFO,"String_Node_Str" + file.getAbsolutePath(),e);
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Entry point from the framework into the command execution
 * @param context context for the command.
 */
public void execute(AdminCommandContext context){
  final ActionReport report=context.getActionReport();
  final Logger logger=context.getLogger();
  List<String> matchedVersions=null;
  if (enabled) {
    try {
      VersioningUtils.checkIdentifier(name);
      matchedVersions=new ArrayList<String>(1);
      matchedVersions.add(name);
    }
 catch (    VersioningWildcardException ex) {
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str"));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
catch (    VersioningSyntaxException ex) {
      report.setMessage(ex.getLocalizedMessage());
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
    if (!deployment.isRegistered(name)) {
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",name));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
  }
 else {
    try {
      matchedVersions=versioningService.getMatchedVersions(name,null);
    }
 catch (    VersioningException e) {
      report.failure(logger,e.getMessage());
      return;
    }
    if (matchedVersions.isEmpty()) {
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",name,target));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }
  }
  ActionReport.MessagePart part=report.getTopMessagePart();
  boolean isVersionExpression=VersioningUtils.isVersionExpression(name);
  Iterator it=matchedVersions.iterator();
  while (it.hasNext()) {
    String appName=(String)it.next();
    Application app=applications.getApplication(appName);
    ApplicationRef applicationRef=domain.getApplicationRefInTarget(appName,target);
    if (applicationRef != null) {
      if (isVersionExpression) {
        ActionReport.MessagePart childPart=part.addChild();
        childPart.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",appName,target));
      }
 else {
        report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",name,target));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
      }
    }
 else {
      Transaction t=new Transaction();
      if (app.isLifecycleModule()) {
        handleLifecycleModule(context,t);
        return;
      }
      ReadableArchive archive;
      File file=null;
      DeployCommandParameters commandParams=null;
      Properties contextProps;
      Map<String,Properties> modulePropsMap=null;
      ApplicationConfigInfo savedAppConfig=null;
      try {
        commandParams=app.getDeployParameters(null);
        commandParams.origin=Origin.create_application_ref;
        commandParams.command=Command.create_application_ref;
        commandParams.target=target;
        commandParams.virtualservers=virtualservers;
        commandParams.enabled=enabled;
        if (lbenabled != null) {
          commandParams.lbenabled=lbenabled;
        }
        if (app.containsSnifferType(ServerTags.OSGI)) {
          commandParams.type=DeploymentProperties.OSGI;
        }
        contextProps=app.getDeployProperties();
        modulePropsMap=app.getModulePropertiesMap();
        savedAppConfig=new ApplicationConfigInfo(app);
        URI uri=new URI(app.getLocation());
        file=new File(uri);
        if (!file.exists()) {
          report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",file.getAbsolutePath()));
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          return;
        }
        archive=archiveFactory.openArchive(file);
      }
 catch (      Exception e) {
        logger.log(Level.SEVERE,"String_Node_Str" + file.getAbsolutePath(),e);
        report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
      }
      try {
        final ExtendedDeploymentContext deploymentContext=deployment.getBuilder(logger,commandParams,report).source(archive).build();
        Properties appProps=deploymentContext.getAppProps();
        appProps.putAll(contextProps);
        String location=DeploymentUtils.relativizeWithinDomainIfPossible(new URI(app.getLocation()));
        appProps.setProperty(ServerTags.LOCATION,location);
        String appLocation=appProps.getProperty(Application.APP_LOCATION_PROP_NAME);
        appProps.setProperty(Application.APP_LOCATION_PROP_NAME,DeploymentUtils.relativizeWithinDomainIfPossible(new URI(appLocation)));
        String planLocation=appProps.getProperty(Application.DEPLOYMENT_PLAN_LOCATION_PROP_NAME);
        if (planLocation != null) {
          appProps.setProperty(Application.DEPLOYMENT_PLAN_LOCATION_PROP_NAME,DeploymentUtils.relativizeWithinDomainIfPossible(new URI(planLocation)));
        }
        savedAppConfig.store(appProps);
        if (modulePropsMap != null) {
          deploymentContext.setModulePropsMap(modulePropsMap);
        }
        if (enabled) {
          versioningService.handleDisable(appName,target,deploymentContext.getActionReport());
        }
        if (domain.isCurrentInstanceMatchingTarget(target,appName,server.getName(),null)) {
          deployment.deploy(deployment.getSniffersFromApp(app),deploymentContext);
        }
 else {
          events.send(new Event<DeploymentContext>(Deployment.APPLICATION_PREPARED,deploymentContext),false);
        }
        if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
          try {
            deployment.registerAppInDomainXML(null,deploymentContext,t,true);
          }
 catch (          TransactionFailure e) {
            logger.warning("String_Node_Str" + appName);
          }
        }
        if (!isVersionExpression && DeploymentUtils.isDASTarget(target)) {
          return;
        }
        final ParameterMap paramMap=deployment.prepareInstanceDeployParamMap(deploymentContext);
        final List<String> targets=new ArrayList<String>(Arrays.asList(commandParams.target.split("String_Node_Str")));
        ClusterOperationUtil.replicateCommand("String_Node_Str",FailurePolicy.Error,FailurePolicy.Warn,FailurePolicy.Ignore,targets,context,paramMap,habitat);
      }
 catch (      Exception e) {
        logger.log(Level.SEVERE,"String_Node_Str",e);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      }
 finally {
        try {
          archive.close();
        }
 catch (        IOException e) {
          logger.log(Level.INFO,"String_Node_Str" + file.getAbsolutePath(),e);
        }
      }
    }
  }
}