Program: 29745
Project: 29745
Buggy source:
/** 
 * Set the appropriate context attribute for our work directory.
 */
private void postWorkDirectory(){
  String workDir=getWorkDir();
  if (workDir == null || workDir.length() == 0) {
    String hostName=null;
    String engineName=null;
    String hostWorkDir=null;
    Container parentHost=getParent();
    if (parentHost != null) {
      hostName=parentHost.getName();
      if (parentHost instanceof StandardHost) {
        hostWorkDir=((StandardHost)parentHost).getWorkDir();
      }
      Container parentEngine=parentHost.getParent();
      if (parentEngine != null) {
        engineName=parentEngine.getName();
      }
    }
    if ((hostName == null) || (hostName.length() < 1))     hostName="String_Node_Str";
    if ((engineName == null) || (engineName.length() < 1))     engineName="String_Node_Str";
    String temp=getPath();
    if (temp.startsWith("String_Node_Str"))     temp=temp.substring(1);
    temp=temp.replace('/','_');
    temp=temp.replace('\\','_');
    if (temp.length() < 1)     temp="String_Node_Str";
    if (hostWorkDir != null) {
      workDir=hostWorkDir + File.separator + temp;
    }
 else {
      workDir="String_Node_Str" + File.separator + engineName+ File.separator+ hostName+ File.separator+ temp;
    }
    setWorkDir(workDir);
  }
  File dir=new File(workDir);
  if (!dir.isAbsolute()) {
    File catalinaHome=engineBase();
    String catalinaHomePath=null;
    try {
      catalinaHomePath=catalinaHome.getCanonicalPath();
      dir=new File(catalinaHomePath,workDir);
    }
 catch (    IOException e) {
    }
  }
  dir.mkdirs();
  getServletContext().setAttribute(ServletContext.TEMPDIR,dir);
  context.setAttributeReadOnly(ServletContext.TEMPDIR);
}

Fixed version (ground truth):
/** 
 * Set the appropriate context attribute for our work directory.
 */
private void postWorkDirectory(){
  String workDir=getWorkDir();
  if (workDir == null || workDir.length() == 0) {
    String hostName=null;
    String engineName=null;
    String hostWorkDir=null;
    Container parentHost=getParent();
    if (parentHost != null) {
      hostName=parentHost.getName();
      if (parentHost instanceof StandardHost) {
        hostWorkDir=((StandardHost)parentHost).getWorkDir();
      }
      Container parentEngine=parentHost.getParent();
      if (parentEngine != null) {
        engineName=parentEngine.getName();
      }
    }
    if ((hostName == null) || (hostName.length() < 1))     hostName="String_Node_Str";
    if ((engineName == null) || (engineName.length() < 1))     engineName="String_Node_Str";
    String temp=getPath();
    if (temp.startsWith("String_Node_Str"))     temp=temp.substring(1);
    temp=temp.replace('/','_');
    temp=temp.replace('\\','_');
    if (temp.length() < 1)     temp="String_Node_Str";
    if (hostWorkDir != null) {
      workDir=hostWorkDir + File.separator + temp;
    }
 else {
      workDir="String_Node_Str" + File.separator + engineName+ File.separator+ hostName+ File.separator+ temp;
    }
    setWorkDir(workDir);
  }
  File dir=new File(workDir);
  if (!dir.isAbsolute()) {
    File catalinaHome=engineBase();
    String catalinaHomePath=null;
    try {
      catalinaHomePath=catalinaHome.getCanonicalPath();
      dir=new File(catalinaHomePath,workDir);
    }
 catch (    IOException e) {
    }
  }
  if (!dir.exists() && !dir.mkdirs()) {
    log.log(Level.SEVERE,sm.getString("String_Node_Str",dir.getAbsolutePath()));
  }
  getServletContext().setAttribute(ServletContext.TEMPDIR,dir);
  context.setAttributeReadOnly(ServletContext.TEMPDIR);
}