Program: 29856
Project: 29856
Buggy source:
/** 
 * Creates and configures a web module and adds it to the specified virtual server.
 */
private WebModule loadWebModule(VirtualServer vs,WebModuleConfig wmInfo,String j2eeApplication,Properties deploymentProperties) throws Exception {
  String wmName=wmInfo.getName();
  String wmContextPath=wmInfo.getContextPath();
  if (wmContextPath.indexOf('%') != -1) {
    try {
      RequestUtil.urlDecode(wmContextPath,"String_Node_Str");
    }
 catch (    Exception e) {
      String msg=rb.getString("String_Node_Str");
      msg=MessageFormat.format(msg,wmName,wmContextPath);
      throw new Exception(msg);
    }
  }
  if (wmContextPath.length() == 0 && vs.getDefaultWebModuleID() != null) {
    String msg=rb.getString("String_Node_Str");
    msg=MessageFormat.format(msg,new Object[]{wmName,vs.getID()});
    throw new Exception(msg);
  }
  wmInfo.setWorkDirBase(_appsWorkRoot);
  wmInfo.setStubBaseDir(appsStubRoot);
  String displayContextPath=null;
  if (wmContextPath.length() == 0)   displayContextPath="String_Node_Str";
 else   displayContextPath=wmContextPath;
  Map<String,AdHocServletInfo> adHocPaths=null;
  Map<String,AdHocServletInfo> adHocSubtrees=null;
  WebModule ctx=(WebModule)vs.findChild(wmContextPath);
  if (ctx != null) {
    if (ctx instanceof AdHocWebModule) {
      if (ctx.hasAdHocPaths()) {
        adHocPaths=ctx.getAdHocPaths();
      }
      if (ctx.hasAdHocSubtrees()) {
        adHocSubtrees=ctx.getAdHocSubtrees();
      }
      vs.removeChild(ctx);
    }
 else     if (Constants.DEFAULT_WEB_MODULE_NAME.equals(ctx.getModuleName())) {
      unloadWebModule(wmContextPath,ctx.getJ2EEApplication(),vs.getName(),true,null);
    }
 else     if (!ctx.getAvailable()) {
      ctx.setAvailable(true);
      return ctx;
    }
 else {
      String msg=rb.getString("String_Node_Str");
      throw new Exception(MessageFormat.format(msg,vs.getID(),ctx.getModuleName(),displayContextPath,wmName));
    }
  }
  if (_logger.isLoggable(Level.FINEST)) {
    Object[] params={wmName,vs.getID(),displayContextPath};
    _logger.log(Level.FINEST,"String_Node_Str",params);
  }
  File docBase=null;
  if (JWS_APPCLIENT_MODULE_NAME.equals(wmName)) {
    docBase=new File(System.getProperty("String_Node_Str"));
  }
 else {
    docBase=wmInfo.getLocation();
  }
  ctx=(WebModule)_embedded.createContext(wmName,wmContextPath,docBase,vs.getDefaultContextXmlLocation(),vs.getDefaultWebXmlLocation(),useDOLforDeployment,wmInfo);
  ctx.setUseNaming(false);
  Engine engine=(Engine)vs.getParent();
  if (engine != null) {
    ctx.setEngineName(engine.getName());
    ctx.setJvmRoute(engine.getJvmRoute());
  }
  String j2eeServer=_serverContext.getInstanceName();
  String domain=_serverContext.getDefaultDomainName();
  ctx.setDomain(domain);
  ctx.setJ2EEServer(j2eeServer);
  ctx.setJ2EEApplication(j2eeApplication);
  ctx.setCachingAllowed(false);
  ctx.setCacheControls(vs.getCacheControls());
  ctx.setBean(wmInfo.getBean());
  if (adHocPaths != null) {
    ctx.addAdHocPaths(adHocPaths);
  }
  if (adHocSubtrees != null) {
    ctx.addAdHocSubtrees(adHocSubtrees);
  }
  WebBundleDescriptor wbd=wmInfo.getDescriptor();
  if (wbd != null) {
    ctx.setContextRoot(wbd.getContextRoot());
  }
 else {
    _logger.log(Level.WARNING,"String_Node_Str",wmInfo);
  }
  String wmInfoWorkDir=wmInfo.getWorkDir();
  if (wmInfoWorkDir != null) {
    StringBuilder workDir=new StringBuilder(wmInfo.getWorkDir());
    if (wmName.equals(Constants.DEFAULT_WEB_MODULE_NAME)) {
      workDir.append("String_Node_Str");
      workDir.append(FileUtils.makeFriendlyFilename(vs.getID()));
    }
    ctx.setWorkDir(workDir.toString());
  }
  ClassLoader parentLoader=wmInfo.getParentLoader();
  if (parentLoader == null) {
    parentLoader=_serverContext.getSharedClassLoader();
  }
  ctx.setParentClassLoader(parentLoader);
  if (wbd != null) {
    ctx.configureAlternateDD(wbd);
    ctx.configureWebServices(wbd);
  }
  SunWebApp iasBean=null;
  if (wbd != null) {
    iasBean=wbd.getSunDescriptor();
  }
  ctx.setIasWebAppConfigBean(iasBean);
  ctx.configureMiscSettings(iasBean,vs,displayContextPath);
  if (ctx.getID().startsWith(Constants.DEFAULT_WEB_MODULE_NAME)) {
    ctx.setAlternateDocBases(vs.getProperties());
  }
  Loader loader=ctx.configureLoader(iasBean);
  if (wbd != null && wbd.hasWebServices()) {
    wbd.addExtraAttribute("String_Node_Str",loader);
  }
  ctx.configureSessionSettings(wbd,wmInfo);
  ctx.setI18nInfo();
  if (wbd != null) {
    String resourceType=wmInfo.getObjectType();
    boolean isSystem=resourceType != null && resourceType.startsWith("String_Node_Str");
    if (!wmName.startsWith(Constants.DEFAULT_WEB_MODULE_NAME)) {
      Realm realm=habitat.getByContract(Realm.class);
      if ("String_Node_Str".equals(j2eeApplication)) {
        if (realm != null && realm instanceof RealmInitializer) {
          ((RealmInitializer)realm).initializeRealm(wbd,isSystem,vs.getAuthRealmName());
          ctx.setRealm(realm);
        }
      }
 else {
        if (realm != null && realm instanceof RealmInitializer) {
          ((RealmInitializer)realm).initializeRealm(wbd,isSystem,null);
          ctx.setRealm(realm);
        }
      }
    }
    if (wbd.getApplication() != null && wbd.getApplication().isVirtual()) {
      wbd.visit(new WebValidatorWithoutCL());
    }
  }
  addMimeMappings(ctx,vs.getMimeMap());
  String moduleName=Constants.DEFAULT_WEB_MODULE_NAME;
  String monitoringNodeName=moduleName;
  if (wbd != null && wbd.getApplication() != null) {
    com.sun.enterprise.deployment.Application app=wbd.getApplication();
    ctx.setStandalone(app.isVirtual());
    if (app.isVirtual()) {
      moduleName=app.getRegistrationName();
      monitoringNodeName=wbd.getModuleID();
    }
 else {
      moduleName=wbd.getModuleDescriptor().getArchiveUri();
      StringBuilder sb=new StringBuilder();
      sb.append(app.getRegistrationName()).append(MONITORING_NODE_SEPARATOR).append(moduleName);
      monitoringNodeName=sb.toString().replaceAll("String_Node_Str","String_Node_Str").replaceAll("String_Node_Str","String_Node_Str");
    }
  }
  ctx.setModuleName(moduleName);
  ctx.setMonitoringNodeName(monitoringNodeName);
  List<String> servletNames=new ArrayList<String>();
  if (wbd != null) {
    for (    WebComponentDescriptor webCompDesc : wbd.getWebComponentDescriptors()) {
      if (webCompDesc.isServlet()) {
        servletNames.add(webCompDesc.getCanonicalName());
      }
    }
  }
  webStatsProviderBootstrap.registerApplicationStatsProviders(monitoringNodeName,vs.getName(),servletNames);
  vs.addChild(ctx);
  ctx.loadSessions(deploymentProperties);
  return ctx;
}

Fixed version (ground truth):
/** 
 * Creates and configures a web module and adds it to the specified virtual server.
 */
private WebModule loadWebModule(VirtualServer vs,WebModuleConfig wmInfo,String j2eeApplication,Properties deploymentProperties) throws Exception {
  String wmName=wmInfo.getName();
  String wmContextPath=wmInfo.getContextPath();
  if (wmContextPath.indexOf('%') != -1) {
    try {
      RequestUtil.urlDecode(wmContextPath,"String_Node_Str");
    }
 catch (    Exception e) {
      String msg=rb.getString("String_Node_Str");
      msg=MessageFormat.format(msg,wmName,wmContextPath);
      throw new Exception(msg);
    }
  }
  if (wmContextPath.length() == 0 && vs.getDefaultWebModuleID() != null) {
    String msg=rb.getString("String_Node_Str");
    msg=MessageFormat.format(msg,new Object[]{wmName,vs.getID()});
    throw new Exception(msg);
  }
  wmInfo.setWorkDirBase(_appsWorkRoot);
  wmInfo.setStubBaseDir(appsStubRoot);
  String displayContextPath=null;
  if (wmContextPath.length() == 0)   displayContextPath="String_Node_Str";
 else   displayContextPath=wmContextPath;
  Map<String,AdHocServletInfo> adHocPaths=null;
  Map<String,AdHocServletInfo> adHocSubtrees=null;
  WebModule ctx=(WebModule)vs.findChild(wmContextPath);
  if (ctx != null) {
    if (ctx instanceof AdHocWebModule) {
      if (ctx.hasAdHocPaths()) {
        adHocPaths=ctx.getAdHocPaths();
      }
      if (ctx.hasAdHocSubtrees()) {
        adHocSubtrees=ctx.getAdHocSubtrees();
      }
      vs.removeChild(ctx);
    }
 else     if (Constants.DEFAULT_WEB_MODULE_NAME.equals(ctx.getModuleName())) {
      unloadWebModule(wmContextPath,ctx.getJ2EEApplication(),vs.getName(),true,null);
    }
 else     if (!ctx.getAvailable()) {
      ctx.setAvailable(true);
      return ctx;
    }
 else {
      String msg=rb.getString("String_Node_Str");
      throw new Exception(MessageFormat.format(msg,vs.getID(),ctx.getModuleName(),displayContextPath,wmName));
    }
  }
  if (_logger.isLoggable(Level.FINEST)) {
    Object[] params={wmName,vs.getID(),displayContextPath};
    _logger.log(Level.FINEST,"String_Node_Str",params);
  }
  File docBase=null;
  if (JWS_APPCLIENT_MODULE_NAME.equals(wmName)) {
    docBase=new File(System.getProperty("String_Node_Str"));
  }
 else {
    docBase=wmInfo.getLocation();
  }
  ctx=(WebModule)_embedded.createContext(wmName,wmContextPath,docBase,vs.getDefaultContextXmlLocation(),vs.getDefaultWebXmlLocation(),useDOLforDeployment,wmInfo);
  ctx.setUseNaming(false);
  Engine engine=(Engine)vs.getParent();
  if (engine != null) {
    ctx.setEngineName(engine.getName());
    ctx.setJvmRoute(engine.getJvmRoute());
  }
  String j2eeServer=_serverContext.getInstanceName();
  String domain=_serverContext.getDefaultDomainName();
  ctx.setDomain(domain);
  ctx.setJ2EEServer(j2eeServer);
  ctx.setJ2EEApplication(j2eeApplication);
  ctx.setCacheControls(vs.getCacheControls());
  ctx.setBean(wmInfo.getBean());
  if (adHocPaths != null) {
    ctx.addAdHocPaths(adHocPaths);
  }
  if (adHocSubtrees != null) {
    ctx.addAdHocSubtrees(adHocSubtrees);
  }
  WebBundleDescriptor wbd=wmInfo.getDescriptor();
  if (wbd != null) {
    ctx.setContextRoot(wbd.getContextRoot());
  }
 else {
    _logger.log(Level.WARNING,"String_Node_Str",wmInfo);
  }
  String wmInfoWorkDir=wmInfo.getWorkDir();
  if (wmInfoWorkDir != null) {
    StringBuilder workDir=new StringBuilder(wmInfo.getWorkDir());
    if (wmName.equals(Constants.DEFAULT_WEB_MODULE_NAME)) {
      workDir.append("String_Node_Str");
      workDir.append(FileUtils.makeFriendlyFilename(vs.getID()));
    }
    ctx.setWorkDir(workDir.toString());
  }
  ClassLoader parentLoader=wmInfo.getParentLoader();
  if (parentLoader == null) {
    parentLoader=_serverContext.getSharedClassLoader();
  }
  ctx.setParentClassLoader(parentLoader);
  if (wbd != null) {
    ctx.configureAlternateDD(wbd);
    ctx.configureWebServices(wbd);
  }
  SunWebApp iasBean=null;
  if (wbd != null) {
    iasBean=wbd.getSunDescriptor();
  }
  ctx.setIasWebAppConfigBean(iasBean);
  ctx.configureMiscSettings(iasBean,vs,displayContextPath);
  if (ctx.getID().startsWith(Constants.DEFAULT_WEB_MODULE_NAME)) {
    ctx.setAlternateDocBases(vs.getProperties());
  }
  Loader loader=ctx.configureLoader(iasBean);
  if (wbd != null && wbd.hasWebServices()) {
    wbd.addExtraAttribute("String_Node_Str",loader);
  }
  ctx.configureSessionSettings(wbd,wmInfo);
  ctx.setI18nInfo();
  if (wbd != null) {
    String resourceType=wmInfo.getObjectType();
    boolean isSystem=resourceType != null && resourceType.startsWith("String_Node_Str");
    if (!wmName.startsWith(Constants.DEFAULT_WEB_MODULE_NAME)) {
      Realm realm=habitat.getByContract(Realm.class);
      if ("String_Node_Str".equals(j2eeApplication)) {
        if (realm != null && realm instanceof RealmInitializer) {
          ((RealmInitializer)realm).initializeRealm(wbd,isSystem,vs.getAuthRealmName());
          ctx.setRealm(realm);
        }
      }
 else {
        if (realm != null && realm instanceof RealmInitializer) {
          ((RealmInitializer)realm).initializeRealm(wbd,isSystem,null);
          ctx.setRealm(realm);
        }
      }
    }
    if (wbd.getApplication() != null && wbd.getApplication().isVirtual()) {
      wbd.visit(new WebValidatorWithoutCL());
    }
  }
  addMimeMappings(ctx,vs.getMimeMap());
  String moduleName=Constants.DEFAULT_WEB_MODULE_NAME;
  String monitoringNodeName=moduleName;
  if (wbd != null && wbd.getApplication() != null) {
    com.sun.enterprise.deployment.Application app=wbd.getApplication();
    ctx.setStandalone(app.isVirtual());
    if (app.isVirtual()) {
      moduleName=app.getRegistrationName();
      monitoringNodeName=wbd.getModuleID();
    }
 else {
      moduleName=wbd.getModuleDescriptor().getArchiveUri();
      StringBuilder sb=new StringBuilder();
      sb.append(app.getRegistrationName()).append(MONITORING_NODE_SEPARATOR).append(moduleName);
      monitoringNodeName=sb.toString().replaceAll("String_Node_Str","String_Node_Str").replaceAll("String_Node_Str","String_Node_Str");
    }
  }
  ctx.setModuleName(moduleName);
  ctx.setMonitoringNodeName(monitoringNodeName);
  List<String> servletNames=new ArrayList<String>();
  if (wbd != null) {
    for (    WebComponentDescriptor webCompDesc : wbd.getWebComponentDescriptors()) {
      if (webCompDesc.isServlet()) {
        servletNames.add(webCompDesc.getCanonicalName());
      }
    }
  }
  webStatsProviderBootstrap.registerApplicationStatsProviders(monitoringNodeName,vs.getName(),servletNames);
  vs.addChild(ctx);
  ctx.loadSessions(deploymentProperties);
  return ctx;
}