Program: 24671
Project: 24671
Buggy source:
/** 
 * Generate an error page based on the given exception. Utilizes the system error stylesheet to produce a nicely formatted HTML page.
 * @param req  The HTTP request we're responding to
 * @param res  The HTTP result to write to
 * @param exc  The exception producing the error. If it's aDynaXMLException, the attributes will be passed to the error stylesheet.
 */
protected void genErrorPage(HttpServletRequest req,HttpServletResponse res,Exception exc){
  String strStackTrace;
  String[] saxonErrors=XTFSaxonErrorListener.getThreadErrors();
  if (saxonErrors != null) {
    StringBuffer buf=new StringBuffer();
    for (    String s : saxonErrors)     buf.append(s + "String_Node_Str");
    buf.append("String_Node_Str");
    strStackTrace=buf.toString();
  }
 else {
    ByteArrayOutputStream traceStream=new ByteArrayOutputStream();
    exc.printStackTrace(new PrintStream(traceStream));
    strStackTrace=traceStream.toString();
  }
  String htmlStackTrace=makeHtmlString(strStackTrace);
  try {
    ServletOutputStream out=res.getOutputStream();
    Transformer trans;
    String raw=req.getParameter("String_Node_Str");
    if (raw == null)     raw=(String)req.getAttribute("String_Node_Str");
    if ("String_Node_Str".equals(raw) || "String_Node_Str".equals(raw) || "String_Node_Str".equals(raw)) {
      res.setContentType("String_Node_Str");
      trans=IndexUtil.createTransformer();
      Properties props=trans.getOutputProperties();
      props.put("String_Node_Str","String_Node_Str");
      props.put("String_Node_Str","String_Node_Str");
      trans.setOutputProperties(props);
    }
 else {
      TextConfig config=getConfig();
      Templates pss=stylesheetCache.find(errorGenSheet.get());
      res.setContentType(calcMimeType(pss));
      trans=pss.newTransformer();
      stuffAttribs(trans,req);
      stuffAttribs(trans,config.attribs);
    }
    String className=exc.getClass().getName().replaceAll("String_Node_Str","String_Node_Str").replaceAll("String_Node_Str","String_Node_Str").replaceAll("String_Node_Str","String_Node_Str").replaceAll("String_Node_Str","String_Node_Str");
    StringBuffer doc=new StringBuffer(2048);
    doc.append("String_Node_Str" + className + "String_Node_Str");
    trans.setParameter("String_Node_Str",new StringValue(className));
    String msg=makeHtmlString(exc.getMessage());
    if (!isEmpty(msg)) {
      doc.append("String_Node_Str" + msg + "String_Node_Str");
      trans.setParameter("String_Node_Str",new StringValue(msg));
    }
    if (exc instanceof GeneralException) {
      GeneralException bve=(GeneralException)exc;
      for (Iterator i=bve.attribs.iterator(); i.hasNext(); ) {
        Attrib a=(Attrib)i.next();
        doc.append("String_Node_Str" + a.key + "String_Node_Str");
        doc.append(a.value);
        doc.append("String_Node_Str" + a.key + "String_Node_Str");
        trans.setParameter(a.key,new StringValue(a.value));
      }
    }
    boolean isSocketExc=false;
    HashSet<Object> alreadyTraversed=new HashSet();
    for (Throwable t=exc; !isSocketExc && t != null && !alreadyTraversed.contains(t); ) {
      alreadyTraversed.add(t);
      if (t instanceof SocketException)       isSocketExc=true;
 else       if (t.getClass().getName().contains("String_Node_Str"))       isSocketExc=true;
 else       if (t instanceof TransformerException && ((TransformerException)t).getException() != null)       t=((TransformerException)t).getException();
 else       if (t.getCause() != null)       t=t.getCause();
    }
    boolean isSevere=true;
    if (!(exc instanceof ExcessiveWorkException) && !(exc instanceof TermLimitException) && !(exc instanceof SocketException)&& !isSocketExc&& (!(exc instanceof GeneralException) || ((GeneralException)exc).isSevere())) {
      isSevere=false;
    }
    if (isSevere) {
      doc.append("String_Node_Str" + htmlStackTrace + "String_Node_Str");
      trans.setParameter("String_Node_Str",new StringValue(htmlStackTrace));
    }
    doc.append("String_Node_Str" + className + "String_Node_Str");
    if (isSocketExc)     Trace.warning("String_Node_Str" + msg.toString());
 else     if (isSevere)     Trace.error("String_Node_Str" + doc.toString().replaceAll("String_Node_Str","String_Node_Str"));
    if (!res.isCommitted()) {
      StreamSource src=new StreamSource(new StringReader(doc.toString()));
      StreamResult dst=new StreamResult(out);
      trans.transform(src,dst);
    }
  }
 catch (  Exception e) {
    try {
      Trace.error("String_Node_Str" + e.toString() + "String_Node_Str"+ "String_Node_Str"+ exc.toString()+ "String_Node_Str"+ strStackTrace);
      if (!res.isCommitted()) {
        ServletOutputStream out=res.getOutputStream();
        out.println("String_Node_Str");
        out.println("String_Node_Str");
        out.println("String_Node_Str" + e.toString() + "String_Node_Str");
        out.println("String_Node_Str" + exc.toString() + "String_Node_Str"+ htmlStackTrace);
        out.println("String_Node_Str");
      }
    }
 catch (    IOException e2) {
    }
  }
}

Fixed version (ground truth):
/** 
 * Generate an error page based on the given exception. Utilizes the system error stylesheet to produce a nicely formatted HTML page.
 * @param req  The HTTP request we're responding to
 * @param res  The HTTP result to write to
 * @param exc  The exception producing the error. If it's aDynaXMLException, the attributes will be passed to the error stylesheet.
 */
protected void genErrorPage(HttpServletRequest req,HttpServletResponse res,Exception exc){
  String strStackTrace;
  String[] saxonErrors=XTFSaxonErrorListener.getThreadErrors();
  if (saxonErrors != null) {
    StringBuffer buf=new StringBuffer();
    for (    String s : saxonErrors)     buf.append(s + "String_Node_Str");
    buf.append("String_Node_Str");
    strStackTrace=buf.toString();
  }
 else {
    ByteArrayOutputStream traceStream=new ByteArrayOutputStream();
    exc.printStackTrace(new PrintStream(traceStream));
    strStackTrace=traceStream.toString();
  }
  String htmlStackTrace=makeHtmlString(strStackTrace);
  try {
    ServletOutputStream out=res.getOutputStream();
    Transformer trans;
    String raw=req.getParameter("String_Node_Str");
    if (raw == null)     raw=(String)req.getAttribute("String_Node_Str");
    if ("String_Node_Str".equals(raw) || "String_Node_Str".equals(raw) || "String_Node_Str".equals(raw)) {
      res.setContentType("String_Node_Str");
      trans=IndexUtil.createTransformer();
      Properties props=trans.getOutputProperties();
      props.put("String_Node_Str","String_Node_Str");
      props.put("String_Node_Str","String_Node_Str");
      trans.setOutputProperties(props);
    }
 else {
      TextConfig config=getConfig();
      Templates pss=stylesheetCache.find(errorGenSheet.get());
      res.setContentType(calcMimeType(pss));
      trans=pss.newTransformer();
      stuffAttribs(trans,req);
      stuffAttribs(trans,config.attribs);
    }
    String className=exc.getClass().getName().replaceAll("String_Node_Str","String_Node_Str").replaceAll("String_Node_Str","String_Node_Str").replaceAll("String_Node_Str","String_Node_Str").replaceAll("String_Node_Str","String_Node_Str");
    StringBuffer doc=new StringBuffer(2048);
    doc.append("String_Node_Str" + className + "String_Node_Str");
    trans.setParameter("String_Node_Str",new StringValue(className));
    String msg=makeHtmlString(exc.getMessage());
    if (!isEmpty(msg)) {
      doc.append("String_Node_Str" + msg + "String_Node_Str");
      trans.setParameter("String_Node_Str",new StringValue(msg));
    }
    if (exc instanceof GeneralException) {
      GeneralException bve=(GeneralException)exc;
      for (Iterator i=bve.attribs.iterator(); i.hasNext(); ) {
        Attrib a=(Attrib)i.next();
        doc.append("String_Node_Str" + a.key + "String_Node_Str");
        doc.append(a.value);
        doc.append("String_Node_Str" + a.key + "String_Node_Str");
        trans.setParameter(a.key,new StringValue(a.value));
      }
    }
    boolean isSocketExc=false;
    HashSet<Object> alreadyTraversed=new HashSet();
    for (Throwable t=exc; !isSocketExc && t != null && !alreadyTraversed.contains(t); ) {
      alreadyTraversed.add(t);
      if (t instanceof SocketException)       isSocketExc=true;
 else       if (t.getClass().getName().contains("String_Node_Str"))       isSocketExc=true;
 else       if (t instanceof TransformerException && ((TransformerException)t).getException() != null)       t=((TransformerException)t).getException();
 else       if (t.getCause() != null)       t=t.getCause();
    }
    boolean isNormalException=isSocketExc || exc instanceof ExcessiveWorkException || exc instanceof TermLimitException|| exc instanceof SocketException|| (exc instanceof GeneralException && !((GeneralException)exc).isSevere());
    if (!isNormalException) {
      doc.append("String_Node_Str" + htmlStackTrace + "String_Node_Str");
      trans.setParameter("String_Node_Str",new StringValue(htmlStackTrace));
    }
    doc.append("String_Node_Str" + className + "String_Node_Str");
    if (isSocketExc)     Trace.warning("String_Node_Str" + msg.toString());
 else     if (!isNormalException)     Trace.error("String_Node_Str" + doc.toString().replaceAll("String_Node_Str","String_Node_Str"));
    if (!res.isCommitted()) {
      StreamSource src=new StreamSource(new StringReader(doc.toString()));
      StreamResult dst=new StreamResult(out);
      trans.transform(src,dst);
    }
  }
 catch (  Exception e) {
    try {
      Trace.error("String_Node_Str" + e.toString() + "String_Node_Str"+ "String_Node_Str"+ exc.toString()+ "String_Node_Str"+ strStackTrace);
      if (!res.isCommitted()) {
        ServletOutputStream out=res.getOutputStream();
        out.println("String_Node_Str");
        out.println("String_Node_Str");
        out.println("String_Node_Str" + e.toString() + "String_Node_Str");
        out.println("String_Node_Str" + exc.toString() + "String_Node_Str"+ htmlStackTrace);
        out.println("String_Node_Str");
      }
    }
 catch (    IOException e2) {
    }
  }
}