Program: 30055
Project: 30055
Buggy source:
public ApplicationInfo deploy(Collection<Sniffer> sniffers,final ExtendedDeploymentContext context){
  long operationStartTime=Calendar.getInstance().getTimeInMillis();
  events.send(new Event<DeploymentContext>(Deployment.DEPLOYMENT_START,context));
  final ActionReport report=context.getActionReport();
  final DeployCommandParameters commandParams=context.getCommandParameters(DeployCommandParameters.class);
  final String appName=commandParams.name();
  if (commandParams.origin == OpsParams.Origin.deploy && appRegistry.get(appName) != null) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",appName));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return null;
  }
  if (commandParams.virtualservers == null) {
    commandParams.virtualservers=getVirtualServers(commandParams.target);
  }
  if (commandParams.enabled == null) {
    commandParams.enabled=Boolean.TRUE;
  }
  ProgressTracker tracker=new ProgressTracker(){
    public void actOn(    Logger logger){
      for (      EngineRef module : get("String_Node_Str",EngineRef.class)) {
        try {
          module.stop(context);
        }
 catch (        Exception e) {
        }
      }
      try {
        PreDestroy.class.cast(context).preDestroy();
      }
 catch (      Exception e) {
      }
      for (      EngineRef module : get("String_Node_Str",EngineRef.class)) {
        try {
          module.unload(context);
        }
 catch (        Exception e) {
        }
      }
      try {
        ApplicationInfo appInfo=appRegistry.get(appName);
        if (appInfo != null) {
          events.send(new Event<ApplicationInfo>(Deployment.APPLICATION_DISABLED,appInfo));
        }
      }
 catch (      Exception e) {
      }
      for (      EngineRef module : get("String_Node_Str",EngineRef.class)) {
        try {
          module.clean(context);
        }
 catch (        Exception e) {
        }
      }
      if (!commandParams.keepfailedstubs) {
        try {
          context.clean();
        }
 catch (        Exception e) {
        }
      }
      appRegistry.remove(appName);
    }
  }
;
  context.addTransientAppMetaData(ExtendedDeploymentContext.TRACKER,tracker);
  context.setPhase(DeploymentContextImpl.Phase.PREPARE);
  ApplicationInfo appInfo=null;
  try {
    ArchiveHandler handler=context.getArchiveHandler();
    if (handler == null) {
      handler=getArchiveHandler(context.getSource(),commandParams.type);
      context.setArchiveHandler(handler);
    }
    DeploymentTracing tracing=context.getModuleMetaData(DeploymentTracing.class);
    if (tracing != null) {
      tracing.addMark(DeploymentTracing.Mark.ARCHIVE_HANDLER_OBTAINED);
    }
    if (handler == null) {
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",context.getSourceDir()));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return null;
    }
    ClassLoaderHierarchy clh=habitat.getByContract(ClassLoaderHierarchy.class);
    if (tracing != null) {
      tracing.addMark(DeploymentTracing.Mark.CLASS_LOADER_HIERARCHY);
    }
    context.createDeploymentClassLoader(clh,handler);
    if (tracing != null) {
      tracing.addMark(DeploymentTracing.Mark.CLASS_LOADER_CREATED);
    }
    getDeployableTypes(context);
    if (tracing != null) {
      tracing.addMark(DeploymentTracing.Mark.PARSING_DONE);
    }
    final ClassLoader cloader=context.getClassLoader();
    final ClassLoader currentCL=Thread.currentThread().getContextClassLoader();
    try {
      Thread.currentThread().setContextClassLoader(cloader);
      if (sniffers != null && logger.isLoggable(Level.FINE)) {
        for (        Sniffer sniffer : sniffers) {
          logger.fine("String_Node_Str" + sniffer.getModuleType());
        }
      }
      List<EngineInfo> sortedEngineInfos=setupContainerInfos(handler,sniffers,context);
      if (tracing != null) {
        tracing.addMark(DeploymentTracing.Mark.CONTAINERS_SETUP_DONE);
      }
      if (logger.isLoggable(Level.FINE)) {
        for (        EngineInfo info : sortedEngineInfos) {
          logger.fine("String_Node_Str" + info.getSniffer().getModuleType());
        }
      }
      if (sortedEngineInfos == null || sortedEngineInfos.isEmpty()) {
        report.failure(logger,localStrings.getLocalString("String_Node_Str","String_Node_Str",context.getSource().getName()));
        tracker.actOn(logger);
        return null;
      }
      ApplicationInfo tempAppInfo=new ApplicationInfo(events,context.getSource(),appName);
      for (      Object m : context.getModuleMetadata()) {
        tempAppInfo.addMetaData(m);
      }
      tempAppInfo.setIsJavaEEApp(sortedEngineInfos);
      context.getSource().setExtraData(Boolean.class,tempAppInfo.isJavaEEApp());
      appRegistry.add(appName,tempAppInfo);
      try {
        notifyLifecycleInterceptorsBefore(ExtendedDeploymentContext.Phase.PREPARE,context);
      }
 catch (      Throwable interceptorException) {
        report.failure(logger,"String_Node_Str",null);
        report.setFailureCause(interceptorException);
        logger.log(Level.SEVERE,interceptorException.getMessage(),interceptorException);
        tracker.actOn(logger);
        return null;
      }
      events.send(new Event<DeploymentContext>(Deployment.DEPLOYMENT_BEFORE_CLASSLOADER_CREATION,context),false);
      context.createApplicationClassLoader(clh,handler);
      if (tracing != null) {
        tracing.addMark(DeploymentTracing.Mark.CLASS_LOADER_CREATED);
      }
      ModuleInfo moduleInfo=null;
      try {
        moduleInfo=prepareModule(sortedEngineInfos,appName,context,tracker);
      }
 catch (      Throwable prepareException) {
        prepareException.printStackTrace();
        report.failure(logger,"String_Node_Str",null);
        report.setFailureCause(prepareException);
        logger.log(Level.SEVERE,prepareException.getMessage(),prepareException);
        tracker.actOn(logger);
        return null;
      }
      appInfo=context.getModuleMetaData(ApplicationInfo.class);
      if (appInfo == null) {
        appInfo=new ApplicationInfo(events,context.getSource(),appName);
        appInfo.addModule(moduleInfo);
        for (        Object m : context.getModuleMetadata()) {
          moduleInfo.addMetaData(m);
          appInfo.addMetaData(m);
        }
      }
 else {
        for (        EngineRef ref : moduleInfo.getEngineRefs()) {
          appInfo.add(ref);
        }
      }
      appRegistry.remove(appName);
      appInfo.setIsJavaEEApp(sortedEngineInfos);
      appRegistry.add(appName,appInfo);
      notifyLifecycleInterceptorsAfter(ExtendedDeploymentContext.Phase.PREPARE,context);
      if (tracing != null) {
        tracing.addMark(DeploymentTracing.Mark.PREPARED);
      }
      context.setPhase(DeploymentContextImpl.Phase.PREPARED);
      Thread.currentThread().setContextClassLoader(context.getClassLoader());
      appInfo.setAppClassLoader(context.getClassLoader());
      installTransformers(context);
      events.send(new Event<DeploymentContext>(Deployment.APPLICATION_PREPARED,context),false);
      if (loadOnCurrentInstance(context)) {
        appInfo.setLibraries(commandParams.libraries());
        try {
          notifyLifecycleInterceptorsBefore(ExtendedDeploymentContext.Phase.LOAD,context);
          appInfo.load(context,tracker);
          notifyLifecycleInterceptorsAfter(ExtendedDeploymentContext.Phase.LOAD,context);
          notifyLifecycleInterceptorsBefore(ExtendedDeploymentContext.Phase.START,context);
          appInfo.start(context,tracker);
          notifyLifecycleInterceptorsAfter(ExtendedDeploymentContext.Phase.START,context);
        }
 catch (        Throwable loadException) {
          report.failure(logger,"String_Node_Str",null);
          report.setFailureCause(loadException);
          tracker.actOn(logger);
          return null;
        }
      }
      return appInfo;
    }
  finally {
      context.postDeployClean(false);
      Thread.currentThread().setContextClassLoader(currentCL);
    }
  }
 catch (  Throwable e) {
    report.failure(logger,localStrings.getLocalString("String_Node_Str","String_Node_Str",appName),null);
    report.setFailureCause(e);
    logger.log(Level.SEVERE,e.getMessage(),e);
    tracker.actOn(logger);
    return null;
  }
 finally {
    if (report.getActionExitCode() == ActionReport.ExitCode.SUCCESS) {
      events.send(new Event<ApplicationInfo>(Deployment.DEPLOYMENT_SUCCESS,appInfo));
      long operationTime=Calendar.getInstance().getTimeInMillis() - operationStartTime;
      if (appInfo != null) {
        deploymentLifecycleProbeProvider.applicationDeployedEvent(appName,getApplicationType(appInfo),String.valueOf(operationTime));
      }
    }
 else {
      events.send(new Event<DeploymentContext>(Deployment.DEPLOYMENT_FAILURE,context));
    }
  }
}

Fixed version (ground truth):
public ApplicationInfo deploy(Collection<Sniffer> sniffers,final ExtendedDeploymentContext context){
  long operationStartTime=Calendar.getInstance().getTimeInMillis();
  events.send(new Event<DeploymentContext>(Deployment.DEPLOYMENT_START,context));
  final ActionReport report=context.getActionReport();
  final DeployCommandParameters commandParams=context.getCommandParameters(DeployCommandParameters.class);
  final String appName=commandParams.name();
  if (commandParams.origin == OpsParams.Origin.deploy && appRegistry.get(appName) != null) {
    report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",appName));
    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    return null;
  }
  if (commandParams.virtualservers == null) {
    commandParams.virtualservers=getVirtualServers(commandParams.target);
  }
  if (commandParams.enabled == null) {
    commandParams.enabled=Boolean.TRUE;
  }
  ProgressTracker tracker=new ProgressTracker(){
    public void actOn(    Logger logger){
      for (      EngineRef module : get("String_Node_Str",EngineRef.class)) {
        try {
          module.stop(context);
        }
 catch (        Exception e) {
        }
      }
      try {
        PreDestroy.class.cast(context).preDestroy();
      }
 catch (      Exception e) {
      }
      for (      EngineRef module : get("String_Node_Str",EngineRef.class)) {
        try {
          module.unload(context);
        }
 catch (        Exception e) {
        }
      }
      try {
        ApplicationInfo appInfo=appRegistry.get(appName);
        if (appInfo != null) {
          events.send(new Event<ApplicationInfo>(Deployment.APPLICATION_DISABLED,appInfo));
        }
      }
 catch (      Exception e) {
      }
      for (      EngineRef module : get("String_Node_Str",EngineRef.class)) {
        try {
          module.clean(context);
        }
 catch (        Exception e) {
        }
      }
      if (!commandParams.keepfailedstubs) {
        try {
          context.clean();
        }
 catch (        Exception e) {
        }
      }
      appRegistry.remove(appName);
    }
  }
;
  context.addTransientAppMetaData(ExtendedDeploymentContext.TRACKER,tracker);
  context.setPhase(DeploymentContextImpl.Phase.PREPARE);
  ApplicationInfo appInfo=null;
  try {
    ArchiveHandler handler=context.getArchiveHandler();
    if (handler == null) {
      handler=getArchiveHandler(context.getSource(),commandParams.type);
      context.setArchiveHandler(handler);
    }
    DeploymentTracing tracing=context.getModuleMetaData(DeploymentTracing.class);
    if (tracing != null) {
      tracing.addMark(DeploymentTracing.Mark.ARCHIVE_HANDLER_OBTAINED);
    }
    if (handler == null) {
      report.setMessage(localStrings.getLocalString("String_Node_Str","String_Node_Str",context.getSourceDir()));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return null;
    }
    ClassLoaderHierarchy clh=habitat.getByContract(ClassLoaderHierarchy.class);
    if (tracing != null) {
      tracing.addMark(DeploymentTracing.Mark.CLASS_LOADER_HIERARCHY);
    }
    context.createDeploymentClassLoader(clh,handler);
    if (tracing != null) {
      tracing.addMark(DeploymentTracing.Mark.CLASS_LOADER_CREATED);
    }
    getDeployableTypes(context);
    if (tracing != null) {
      tracing.addMark(DeploymentTracing.Mark.PARSING_DONE);
    }
    final ClassLoader cloader=context.getClassLoader();
    final ClassLoader currentCL=Thread.currentThread().getContextClassLoader();
    try {
      Thread.currentThread().setContextClassLoader(cloader);
      if (sniffers != null && logger.isLoggable(Level.FINE)) {
        for (        Sniffer sniffer : sniffers) {
          logger.fine("String_Node_Str" + sniffer.getModuleType());
        }
      }
      List<EngineInfo> sortedEngineInfos=setupContainerInfos(handler,sniffers,context);
      if (tracing != null) {
        tracing.addMark(DeploymentTracing.Mark.CONTAINERS_SETUP_DONE);
      }
      if (logger.isLoggable(Level.FINE)) {
        for (        EngineInfo info : sortedEngineInfos) {
          logger.fine("String_Node_Str" + info.getSniffer().getModuleType());
        }
      }
      if (sortedEngineInfos == null || sortedEngineInfos.isEmpty()) {
        report.failure(logger,localStrings.getLocalString("String_Node_Str","String_Node_Str",context.getSource().getName()));
        tracker.actOn(logger);
        return null;
      }
      ApplicationInfo tempAppInfo=new ApplicationInfo(events,context.getSource(),appName);
      for (      Object m : context.getModuleMetadata()) {
        tempAppInfo.addMetaData(m);
      }
      tempAppInfo.setIsJavaEEApp(sortedEngineInfos);
      context.getSource().setExtraData(Boolean.class,tempAppInfo.isJavaEEApp());
      appRegistry.add(appName,tempAppInfo);
      try {
        notifyLifecycleInterceptorsBefore(ExtendedDeploymentContext.Phase.PREPARE,context);
      }
 catch (      Throwable interceptorException) {
        report.failure(logger,"String_Node_Str",null);
        report.setFailureCause(interceptorException);
        logger.log(Level.SEVERE,interceptorException.getMessage(),interceptorException);
        tracker.actOn(logger);
        return null;
      }
      events.send(new Event<DeploymentContext>(Deployment.DEPLOYMENT_BEFORE_CLASSLOADER_CREATION,context),false);
      context.createApplicationClassLoader(clh,handler);
      if (tracing != null) {
        tracing.addMark(DeploymentTracing.Mark.CLASS_LOADER_CREATED);
      }
      ModuleInfo moduleInfo=null;
      try {
        moduleInfo=prepareModule(sortedEngineInfos,appName,context,tracker);
      }
 catch (      Throwable prepareException) {
        prepareException.printStackTrace();
        report.failure(logger,"String_Node_Str",null);
        report.setFailureCause(prepareException);
        logger.log(Level.SEVERE,prepareException.getMessage(),prepareException);
        tracker.actOn(logger);
        return null;
      }
      appInfo=context.getModuleMetaData(ApplicationInfo.class);
      if (appInfo == null) {
        appInfo=new ApplicationInfo(events,context.getSource(),appName);
        appInfo.addModule(moduleInfo);
        for (        Object m : context.getModuleMetadata()) {
          moduleInfo.addMetaData(m);
          appInfo.addMetaData(m);
        }
      }
 else {
        for (        EngineRef ref : moduleInfo.getEngineRefs()) {
          appInfo.add(ref);
        }
      }
      appRegistry.remove(appName);
      appInfo.setIsJavaEEApp(sortedEngineInfos);
      appRegistry.add(appName,appInfo);
      notifyLifecycleInterceptorsAfter(ExtendedDeploymentContext.Phase.PREPARE,context);
      if (tracing != null) {
        tracing.addMark(DeploymentTracing.Mark.PREPARED);
      }
      context.setPhase(DeploymentContextImpl.Phase.PREPARED);
      Thread.currentThread().setContextClassLoader(context.getClassLoader());
      appInfo.setAppClassLoader(context.getClassLoader());
      events.send(new Event<DeploymentContext>(Deployment.APPLICATION_PREPARED,context),false);
      if (loadOnCurrentInstance(context)) {
        appInfo.setLibraries(commandParams.libraries());
        try {
          notifyLifecycleInterceptorsBefore(ExtendedDeploymentContext.Phase.LOAD,context);
          appInfo.load(context,tracker);
          notifyLifecycleInterceptorsAfter(ExtendedDeploymentContext.Phase.LOAD,context);
          notifyLifecycleInterceptorsBefore(ExtendedDeploymentContext.Phase.START,context);
          appInfo.start(context,tracker);
          notifyLifecycleInterceptorsAfter(ExtendedDeploymentContext.Phase.START,context);
        }
 catch (        Throwable loadException) {
          report.failure(logger,"String_Node_Str",null);
          report.setFailureCause(loadException);
          tracker.actOn(logger);
          return null;
        }
      }
      return appInfo;
    }
  finally {
      context.postDeployClean(false);
      Thread.currentThread().setContextClassLoader(currentCL);
    }
  }
 catch (  Throwable e) {
    report.failure(logger,localStrings.getLocalString("String_Node_Str","String_Node_Str",appName),null);
    report.setFailureCause(e);
    logger.log(Level.SEVERE,e.getMessage(),e);
    tracker.actOn(logger);
    return null;
  }
 finally {
    if (report.getActionExitCode() == ActionReport.ExitCode.SUCCESS) {
      events.send(new Event<ApplicationInfo>(Deployment.DEPLOYMENT_SUCCESS,appInfo));
      long operationTime=Calendar.getInstance().getTimeInMillis() - operationStartTime;
      if (appInfo != null) {
        deploymentLifecycleProbeProvider.applicationDeployedEvent(appName,getApplicationType(appInfo),String.valueOf(operationTime));
      }
    }
 else {
      events.send(new Event<DeploymentContext>(Deployment.DEPLOYMENT_FAILURE,context));
    }
  }
}