Program: 29852
Project: 29852
Buggy source:
/** 
 * Registers the given <tt>Context</tt> with this <tt>VirtualServer</tt> at the given context root. <p>If this <tt>VirtualServer</tt> has already been started, the given <tt>context</tt> will be started as well.
 */
public void addContext(Context context,String contextRoot) throws ConfigException, GlassFishException {
  if (_logger.isLoggable(Level.FINE)) {
    _logger.log(Level.FINE,"String_Node_Str" + getName() + "String_Node_Str"+ contextRoot);
  }
  if (!(context instanceof ContextFacade)) {
    return;
  }
  if (!contextRoot.startsWith("String_Node_Str")) {
    contextRoot="String_Node_Str" + contextRoot;
  }
  ExtendedDeploymentContext deploymentContext=null;
  try {
    if (factory == null)     factory=services.byType(ArchiveFactory.class).get();
    ContextFacade facade=(ContextFacade)context;
    File docRoot=facade.getDocRoot();
    ClassLoader classLoader=facade.getClassLoader();
    ReadableArchive archive=factory.openArchive(docRoot);
    if (report == null)     report=new PlainTextActionReporter();
    ServerEnvironment env=services.forContract(ServerEnvironment.class).get();
    DeployCommandParameters params=new DeployCommandParameters();
    params.contextroot=contextRoot;
    params.enabled=Boolean.FALSE;
    params.origin=OpsParams.Origin.deploy;
    params.virtualservers=getName();
    params.target="String_Node_Str";
    ExtendedDeploymentContext initialContext=new DeploymentContextImpl(report,_logger,archive,params,env);
    if (deployment == null)     deployment=services.forContract(Deployment.class).get();
    ArchiveHandler archiveHandler=deployment.getArchiveHandler(archive);
    if (archiveHandler == null) {
      throw new RuntimeException("String_Node_Str");
    }
    params.name=archiveHandler.getDefaultApplicationName(archive,initialContext);
    Applications apps=domain.getApplications();
    ApplicationInfo appInfo=deployment.get(params.name);
    ApplicationRef appRef=domain.getApplicationRefInServer(params.target,params.name);
    if (appInfo != null) {
      if (appRef != null && appRef.getVirtualServers().contains(getName())) {
        throw new ConfigException("String_Node_Str" + params.name + "String_Node_Str"+ getName());
      }
 else {
        String virtualServers=appRef.getVirtualServers();
        virtualServers=virtualServers + "String_Node_Str" + getName();
        params.virtualservers=virtualServers;
        params.force=Boolean.TRUE;
        if (_logger.isLoggable(Level.FINE)) {
          _logger.log(Level.FINE,"String_Node_Str" + getName() + "String_Node_Str"+ params.name);
        }
        return;
      }
    }
    deploymentContext=deployment.getBuilder(_logger,params,report).source(archive).archiveHandler(archiveHandler).build(initialContext);
    Properties properties=new Properties();
    deploymentContext.getAppProps().putAll(properties);
    if (classLoader != null) {
      ClassLoader parentCL=clh.createApplicationParentCL(classLoader,deploymentContext);
      ClassLoader cl=archiveHandler.getClassLoader(parentCL,deploymentContext);
      deploymentContext.setClassLoader(cl);
    }
    ApplicationConfigInfo savedAppConfig=new ApplicationConfigInfo(apps.getModule(com.sun.enterprise.config.serverbeans.Application.class,params.name));
    Properties appProps=deploymentContext.getAppProps();
    String appLocation=DeploymentUtils.relativizeWithinDomainIfPossible(deploymentContext.getSource().getURI());
    appProps.setProperty(ServerTags.LOCATION,appLocation);
    appProps.setProperty(ServerTags.OBJECT_TYPE,"String_Node_Str");
    appProps.setProperty(ServerTags.CONTEXT_ROOT,contextRoot);
    savedAppConfig.store(appProps);
    Transaction t=deployment.prepareAppConfigChanges(deploymentContext);
    appInfo=deployment.deploy(deploymentContext);
    if (appInfo != null) {
      facade.setAppName(appInfo.getName());
      if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE,"String_Node_Str" + getName() + "String_Node_Str"+ appInfo.getName());
      }
      deployment.registerAppInDomainXML(appInfo,deploymentContext,t);
    }
 else {
      if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
        throw new ConfigException(report.getMessage());
      }
    }
    File file=null;
    boolean delete=true;
    com.sun.enterprise.config.serverbeans.Application appBean=apps.getApplication(params.name);
    if (appBean != null) {
      file=new File(deploymentContext.getSource().getURI().getPath(),"String_Node_Str");
      if (file.exists()) {
        delete=false;
      }
      updateWebXml(facade,file);
    }
 else {
      _logger.log(Level.SEVERE,"String_Node_Str" + params.name + "String_Node_Str");
    }
    ReadableArchive source=appInfo.getSource();
    UndeployCommandParameters undeployParams=new UndeployCommandParameters(params.name);
    undeployParams.origin=UndeployCommandParameters.Origin.undeploy;
    undeployParams.target="String_Node_Str";
    ExtendedDeploymentContext undeploymentContext=deployment.getBuilder(_logger,undeployParams,report).source(source).build();
    deployment.undeploy(params.name,undeploymentContext);
    params.origin=DeployCommandParameters.Origin.load;
    params.enabled=Boolean.TRUE;
    archive=factory.openArchive(docRoot);
    deploymentContext=deployment.getBuilder(_logger,params,report).source(archive).build();
    if (classLoader != null) {
      ClassLoader parentCL=clh.createApplicationParentCL(classLoader,deploymentContext);
      archiveHandler=deployment.getArchiveHandler(archive);
      ClassLoader cl=archiveHandler.getClassLoader(parentCL,deploymentContext);
      deploymentContext.setClassLoader(cl);
    }
    deployment.deploy(deploymentContext);
    deployment.updateAppEnabledAttributeInDomainXML(params.name,params.target,true);
    if (_logger.isLoggable(Level.FINE)) {
      _logger.log(Level.FINE,"String_Node_Str" + getName() + "String_Node_Str"+ params.name());
    }
    if (delete) {
      if (file != null) {
        if (file.exists() && !file.delete()) {
          String path=file.toString();
          _logger.log(Level.WARNING,"String_Node_Str",path);
        }
      }
    }
    if (contextRoot.equals("String_Node_Str")) {
      contextRoot="String_Node_Str";
    }
    WebModule wm=(WebModule)findChild(contextRoot);
    if (wm != null) {
      facade.setUnwrappedContext(wm);
      wm.setEmbedded(true);
      if (config != null) {
        wm.setDefaultWebXml(config.getDefaultWebXml());
      }
    }
 else {
      throw new ConfigException("String_Node_Str" + contextRoot);
    }
    if (deploymentContext != null) {
      deploymentContext.postDeployClean(true);
    }
  }
 catch (  Exception ex) {
    if (deployment != null && deploymentContext != null) {
      deploymentContext.clean();
    }
    throw new GlassFishException(ex);
  }
}

Fixed version (ground truth):
/** 
 * Registers the given <tt>Context</tt> with this <tt>VirtualServer</tt> at the given context root. <p>If this <tt>VirtualServer</tt> has already been started, the given <tt>context</tt> will be started as well.
 */
public void addContext(Context context,String contextRoot) throws ConfigException, GlassFishException {
  if (_logger.isLoggable(Level.FINE)) {
    _logger.log(Level.FINE,"String_Node_Str" + getName() + "String_Node_Str"+ contextRoot);
  }
  if (!(context instanceof ContextFacade)) {
    return;
  }
  if (!contextRoot.startsWith("String_Node_Str")) {
    contextRoot="String_Node_Str" + contextRoot;
  }
  ExtendedDeploymentContext deploymentContext=null;
  try {
    if (factory == null)     factory=services.byType(ArchiveFactory.class).get();
    ContextFacade facade=(ContextFacade)context;
    File docRoot=facade.getDocRoot();
    ClassLoader classLoader=facade.getClassLoader();
    ReadableArchive archive=factory.openArchive(docRoot);
    if (report == null)     report=new PlainTextActionReporter();
    ServerEnvironment env=services.forContract(ServerEnvironment.class).get();
    DeployCommandParameters params=new DeployCommandParameters();
    params.contextroot=contextRoot;
    params.enabled=Boolean.FALSE;
    params.origin=OpsParams.Origin.deploy;
    params.virtualservers=getName();
    params.target="String_Node_Str";
    ExtendedDeploymentContext initialContext=new DeploymentContextImpl(report,_logger,archive,params,env);
    if (deployment == null)     deployment=services.forContract(Deployment.class).get();
    ArchiveHandler archiveHandler=deployment.getArchiveHandler(archive);
    if (archiveHandler == null) {
      throw new RuntimeException("String_Node_Str");
    }
    params.name=archiveHandler.getDefaultApplicationName(archive,initialContext);
    Applications apps=domain.getApplications();
    ApplicationInfo appInfo=deployment.get(params.name);
    ApplicationRef appRef=domain.getApplicationRefInServer(params.target,params.name);
    if (appInfo != null && appRef != null) {
      if (appRef.getVirtualServers().contains(getName())) {
        throw new ConfigException("String_Node_Str" + params.name + "String_Node_Str"+ getName());
      }
 else {
        String virtualServers=appRef.getVirtualServers();
        virtualServers=virtualServers + "String_Node_Str" + getName();
        params.virtualservers=virtualServers;
        params.force=Boolean.TRUE;
        if (_logger.isLoggable(Level.FINE)) {
          _logger.log(Level.FINE,"String_Node_Str" + getName() + "String_Node_Str"+ params.name);
        }
        return;
      }
    }
    deploymentContext=deployment.getBuilder(_logger,params,report).source(archive).archiveHandler(archiveHandler).build(initialContext);
    Properties properties=new Properties();
    deploymentContext.getAppProps().putAll(properties);
    if (classLoader != null) {
      ClassLoader parentCL=clh.createApplicationParentCL(classLoader,deploymentContext);
      ClassLoader cl=archiveHandler.getClassLoader(parentCL,deploymentContext);
      deploymentContext.setClassLoader(cl);
    }
    ApplicationConfigInfo savedAppConfig=new ApplicationConfigInfo(apps.getModule(com.sun.enterprise.config.serverbeans.Application.class,params.name));
    Properties appProps=deploymentContext.getAppProps();
    String appLocation=DeploymentUtils.relativizeWithinDomainIfPossible(deploymentContext.getSource().getURI());
    appProps.setProperty(ServerTags.LOCATION,appLocation);
    appProps.setProperty(ServerTags.OBJECT_TYPE,"String_Node_Str");
    appProps.setProperty(ServerTags.CONTEXT_ROOT,contextRoot);
    savedAppConfig.store(appProps);
    Transaction t=deployment.prepareAppConfigChanges(deploymentContext);
    appInfo=deployment.deploy(deploymentContext);
    if (appInfo != null) {
      facade.setAppName(appInfo.getName());
      if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE,"String_Node_Str" + getName() + "String_Node_Str"+ appInfo.getName());
      }
      deployment.registerAppInDomainXML(appInfo,deploymentContext,t);
    }
 else {
      if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
        throw new ConfigException(report.getMessage());
      }
    }
    File file=null;
    boolean delete=true;
    com.sun.enterprise.config.serverbeans.Application appBean=apps.getApplication(params.name);
    if (appBean != null) {
      file=new File(deploymentContext.getSource().getURI().getPath(),"String_Node_Str");
      if (file.exists()) {
        delete=false;
      }
      updateWebXml(facade,file);
    }
 else {
      _logger.log(Level.SEVERE,"String_Node_Str" + params.name + "String_Node_Str");
    }
    ReadableArchive source=appInfo.getSource();
    UndeployCommandParameters undeployParams=new UndeployCommandParameters(params.name);
    undeployParams.origin=UndeployCommandParameters.Origin.undeploy;
    undeployParams.target="String_Node_Str";
    ExtendedDeploymentContext undeploymentContext=deployment.getBuilder(_logger,undeployParams,report).source(source).build();
    deployment.undeploy(params.name,undeploymentContext);
    params.origin=DeployCommandParameters.Origin.load;
    params.enabled=Boolean.TRUE;
    archive=factory.openArchive(docRoot);
    deploymentContext=deployment.getBuilder(_logger,params,report).source(archive).build();
    if (classLoader != null) {
      ClassLoader parentCL=clh.createApplicationParentCL(classLoader,deploymentContext);
      archiveHandler=deployment.getArchiveHandler(archive);
      ClassLoader cl=archiveHandler.getClassLoader(parentCL,deploymentContext);
      deploymentContext.setClassLoader(cl);
    }
    deployment.deploy(deploymentContext);
    deployment.updateAppEnabledAttributeInDomainXML(params.name,params.target,true);
    if (_logger.isLoggable(Level.FINE)) {
      _logger.log(Level.FINE,"String_Node_Str" + getName() + "String_Node_Str"+ params.name());
    }
    if (delete) {
      if (file != null) {
        if (file.exists() && !file.delete()) {
          String path=file.toString();
          _logger.log(Level.WARNING,"String_Node_Str",path);
        }
      }
    }
    if (contextRoot.equals("String_Node_Str")) {
      contextRoot="String_Node_Str";
    }
    WebModule wm=(WebModule)findChild(contextRoot);
    if (wm != null) {
      facade.setUnwrappedContext(wm);
      wm.setEmbedded(true);
      if (config != null) {
        wm.setDefaultWebXml(config.getDefaultWebXml());
      }
    }
 else {
      throw new ConfigException("String_Node_Str" + contextRoot);
    }
    if (deploymentContext != null) {
      deploymentContext.postDeployClean(true);
    }
  }
 catch (  Exception ex) {
    if (deployment != null && deploymentContext != null) {
      deploymentContext.clean();
    }
    throw new GlassFishException(ex);
  }
}