Program: 29746
Project: 29746
Buggy source:
/** 
 * Remove an existing web application, attached to the specified context path.  If this application is successfully removed, a ContainerEvent of type <code>REMOVE_EVENT</code> will be sent to all registered listeners, with the removed <code>Context</code> as an argument. Deletes the web application war file and/or directory if they exist in the Host's appBase.
 * @param contextPath The context path of the application to be removed
 * @param undeploy boolean flag to remove web application from server
 * @exception IllegalArgumentException if the specified context pathis malformed (it must be "" or start with a slash)
 * @exception IllegalArgumentException if the specified context path doesnot identify a currently installed web application
 * @exception IOException if an input/output error occurs duringremoval
 */
public void remove(String contextPath,boolean undeploy) throws IOException {
  if (contextPath == null)   throw new IllegalArgumentException(sm.getString("String_Node_Str"));
  if (!contextPath.equals("String_Node_Str") && !contextPath.startsWith("String_Node_Str"))   throw new IllegalArgumentException(sm.getString("String_Node_Str",contextPath));
  Context context=findDeployedApp(contextPath);
  if (context == null)   throw new IllegalArgumentException(sm.getString("String_Node_Str",contextPath));
  host.log(sm.getString("String_Node_Str",contextPath));
  try {
    File workDir=(File)context.getServletContext().getAttribute(ServletContext.TEMPDIR);
    String configFile=context.getConfigFile();
    host.removeChild(context);
    if (undeploy) {
      boolean isAppBase=false;
      File appBase=new File(host.getAppBase());
      if (!appBase.isAbsolute())       appBase=new File(System.getProperty("String_Node_Str"),host.getAppBase());
      File contextFile=new File(context.getDocBase());
      File baseDir=contextFile.getParentFile();
      if ((baseDir == null) || (appBase.getCanonicalPath().equals(baseDir.getCanonicalPath()))) {
        isAppBase=true;
      }
      boolean isWAR=false;
      if (contextFile.getName().toLowerCase(Locale.ENGLISH).endsWith("String_Node_Str")) {
        isWAR=true;
      }
      if (isAppBase && host.getAutoDeploy()) {
        String filename=contextFile.getName();
        if (isWAR) {
          filename=filename.substring(0,filename.length() - 4);
        }
        if (contextPath.length() == 0 && filename.equals("String_Node_Str") || filename.equals(contextPath.substring(1))) {
          if (!isWAR) {
            long contextLastModified=contextFile.lastModified();
            if (contextFile.isDirectory()) {
              deleteDir(contextFile);
            }
            if (host.isUnpackWARs()) {
              File contextWAR=new File(context.getDocBase() + "String_Node_Str");
              if (contextWAR.exists()) {
                if (contextLastModified > contextWAR.lastModified()) {
                  contextWAR.delete();
                }
              }
            }
          }
 else {
            contextFile.delete();
          }
        }
        if (host.isDeployXML() && (configFile != null)) {
          File docBaseXml=new File(configFile);
          docBaseXml.delete();
        }
      }
      if (workDir == null && context instanceof StandardContext && ((StandardContext)context).getWorkDir() != null) {
        workDir=new File(((StandardContext)context).getWorkPath());
      }
      if (workDir != null && workDir.exists()) {
        deleteDir(workDir);
      }
    }
    host.fireContainerEvent(REMOVE_EVENT,context);
  }
 catch (  Exception e) {
    host.log(sm.getString("String_Node_Str",contextPath),e);
    throw new IOException(e.toString());
  }
}

Fixed version (ground truth):
/** 
 * Remove an existing web application, attached to the specified context path.  If this application is successfully removed, a ContainerEvent of type <code>REMOVE_EVENT</code> will be sent to all registered listeners, with the removed <code>Context</code> as an argument. Deletes the web application war file and/or directory if they exist in the Host's appBase.
 * @param contextPath The context path of the application to be removed
 * @param undeploy boolean flag to remove web application from server
 * @exception IllegalArgumentException if the specified context pathis malformed (it must be "" or start with a slash)
 * @exception IllegalArgumentException if the specified context path doesnot identify a currently installed web application
 * @exception IOException if an input/output error occurs duringremoval
 */
public void remove(String contextPath,boolean undeploy) throws IOException {
  if (contextPath == null)   throw new IllegalArgumentException(sm.getString("String_Node_Str"));
  if (!contextPath.equals("String_Node_Str") && !contextPath.startsWith("String_Node_Str"))   throw new IllegalArgumentException(sm.getString("String_Node_Str",contextPath));
  Context context=findDeployedApp(contextPath);
  if (context == null)   throw new IllegalArgumentException(sm.getString("String_Node_Str",contextPath));
  host.log(sm.getString("String_Node_Str",contextPath));
  try {
    File workDir=(File)context.getServletContext().getAttribute(ServletContext.TEMPDIR);
    String configFile=context.getConfigFile();
    host.removeChild(context);
    if (undeploy) {
      boolean isAppBase=false;
      File appBase=new File(host.getAppBase());
      if (!appBase.isAbsolute())       appBase=new File(System.getProperty("String_Node_Str"),host.getAppBase());
      File contextFile=new File(context.getDocBase());
      File baseDir=contextFile.getParentFile();
      if ((baseDir == null) || (appBase.getCanonicalPath().equals(baseDir.getCanonicalPath()))) {
        isAppBase=true;
      }
      boolean isWAR=false;
      if (contextFile.getName().toLowerCase(Locale.ENGLISH).endsWith("String_Node_Str")) {
        isWAR=true;
      }
      if (isAppBase && host.getAutoDeploy()) {
        String filename=contextFile.getName();
        if (isWAR) {
          filename=filename.substring(0,filename.length() - 4);
        }
        if (contextPath.length() == 0 && filename.equals("String_Node_Str") || filename.equals(contextPath.substring(1))) {
          if (!isWAR) {
            long contextLastModified=contextFile.lastModified();
            if (contextFile.isDirectory()) {
              deleteDir(contextFile);
            }
            if (host.isUnpackWARs()) {
              File contextWAR=new File(context.getDocBase() + "String_Node_Str");
              if (contextWAR.exists()) {
                if (contextLastModified > contextWAR.lastModified()) {
                  deleteFile(contextWAR);
                }
              }
            }
          }
 else {
            deleteFile(contextFile);
          }
        }
        if (host.isDeployXML() && (configFile != null)) {
          File docBaseXml=new File(configFile);
          deleteFile(docBaseXml);
        }
      }
      if (workDir == null && context instanceof StandardContext && ((StandardContext)context).getWorkDir() != null) {
        workDir=new File(((StandardContext)context).getWorkPath());
      }
      if (workDir != null && workDir.exists()) {
        deleteDir(workDir);
      }
    }
    host.fireContainerEvent(REMOVE_EVENT,context);
  }
 catch (  Exception e) {
    host.log(sm.getString("String_Node_Str",contextPath),e);
    throw new IOException(e.toString());
  }
}