Program: 29831
Project: 29831
Buggy source:
/** 
 * Finds and returns information about a web module embedded within a J2EE application, which is identified by a string of the form <code>a:b</code> or <code>a#b</code>, where <code>a</code> is the name of the J2EE application and <code>b</code> is the name of the embedded web module.
 * @return null if <code>id</code> does not identify a web module embeddedwithin a J2EE application.
 */
protected WebModuleConfig findWebModuleInJ2eeApp(Applications appsBean,String id,ApplicationRegistry appRegistry){
  WebModuleConfig wmInfo=null;
  int separatorIndex=id.indexOf(Constants.NAME_SEPARATOR);
  if (separatorIndex == -1) {
    separatorIndex=id.indexOf('#');
  }
  if (separatorIndex != -1) {
    String appID=id.substring(0,separatorIndex);
    String moduleID=id.substring(separatorIndex + 1);
    com.sun.enterprise.config.serverbeans.Application appBean=appsBean.getModule(com.sun.enterprise.config.serverbeans.Application.class,appID);
    if ((appBean != null) && Boolean.valueOf(appBean.getEnabled())) {
      String location=appBean.getLocation();
      String moduleDir=DeploymentUtils.getRelativeEmbeddedModulePath(location,moduleID);
      ApplicationInfo appInfo=appRegistry.get(appID);
      Application app=null;
      if (appInfo != null) {
        app=appInfo.getMetaData(Application.class);
      }
 else {
        Object[] params={id,getID()};
        _logger.log(Level.SEVERE,"String_Node_Str",params);
        return wmInfo;
      }
      WebBundleDescriptor wbd=app.getModuleByTypeAndUri(WebBundleDescriptor.class,moduleID);
      String webUri=wbd.getModuleDescriptor().getArchiveUri();
      String contextRoot=wbd.getModuleDescriptor().getContextRoot();
      if (moduleID.equals(webUri)) {
        StringBuilder dir=new StringBuilder(location);
        dir.append(File.separator);
        dir.append(moduleDir);
        File docroot=new File(dir.toString());
        wmInfo=new WebModuleConfig();
        wbd.setName(moduleID);
        wbd.setContextRoot(contextRoot);
        wmInfo.setDescriptor(wbd);
        wmInfo.setLocation(docroot);
        wmInfo.setParentLoader(EmbeddedWebContainer.class.getClassLoader());
        wmInfo.setAppClassLoader(new WebappClassLoader(wmInfo.getParentLoader()));
      }
    }
 else {
      Object[] params={id,getID()};
      _logger.log(Level.SEVERE,"String_Node_Str",params);
    }
  }
  return wmInfo;
}

Fixed version (ground truth):
/** 
 * Finds and returns information about a web module embedded within a J2EE application, which is identified by a string of the form <code>a:b</code> or <code>a#b</code>, where <code>a</code> is the name of the J2EE application and <code>b</code> is the name of the embedded web module.
 * @return null if <code>id</code> does not identify a web module embeddedwithin a J2EE application.
 */
protected WebModuleConfig findWebModuleInJ2eeApp(Applications appsBean,String id,ApplicationRegistry appRegistry){
  WebModuleConfig wmInfo=null;
  int separatorIndex=id.indexOf(Constants.NAME_SEPARATOR);
  if (separatorIndex == -1) {
    separatorIndex=id.indexOf('#');
  }
  if (separatorIndex != -1) {
    String appID=id.substring(0,separatorIndex);
    String moduleID=id.substring(separatorIndex + 1);
    com.sun.enterprise.config.serverbeans.Application appBean=appsBean.getModule(com.sun.enterprise.config.serverbeans.Application.class,appID);
    if ((appBean != null) && Boolean.valueOf(appBean.getEnabled())) {
      String location=appBean.getLocation();
      String moduleDir=DeploymentUtils.getRelativeEmbeddedModulePath(location,moduleID);
      ApplicationInfo appInfo=appRegistry.get(appID);
      Application app=null;
      if (appInfo != null) {
        app=appInfo.getMetaData(Application.class);
      }
 else {
        Object[] params={id,getID()};
        _logger.log(Level.SEVERE,"String_Node_Str",params);
        return wmInfo;
      }
      WebBundleDescriptor wbd=app.getModuleByTypeAndUri(WebBundleDescriptor.class,moduleID);
      String webUri=wbd.getModuleDescriptor().getArchiveUri();
      String contextRoot=wbd.getModuleDescriptor().getContextRoot();
      if (moduleID.equals(webUri)) {
        StringBuilder dir=new StringBuilder(location);
        dir.append(File.separator);
        dir.append(moduleDir);
        File docroot=new File(dir.toString());
        wmInfo=new WebModuleConfig();
        wbd.setName(moduleID);
        wbd.setContextRoot(contextRoot);
        wmInfo.setDescriptor(wbd);
        wmInfo.setLocation(docroot);
        wmInfo.setParentLoader(EmbeddedWebContainer.class.getClassLoader());
        WebappClassLoader cloader=AccessController.doPrivileged(new PrivilegedAction<WebappClassLoader>(){
          @Override public WebappClassLoader run(){
            return new WebappClassLoader(EmbeddedWebContainer.class.getClassLoader());
          }
        }
);
        wmInfo.setAppClassLoader(cloader);
      }
    }
 else {
      Object[] params={id,getID()};
      _logger.log(Level.SEVERE,"String_Node_Str",params);
    }
  }
  return wmInfo;
}