DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6234>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6234

checkError method of Servlet's PrintWriter is unreliable

           Summary: checkError method of Servlet's PrintWriter is unreliable
           Product: Tomcat 3
           Version: 3.3 Final
          Platform: Other
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Minor
          Priority: Other
         Component: Servlet
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


Tomcat appears to be recycling PrintWriters.  After a particular PrintWriter's
checkError() method returns true, it always returns true (even after it is
recycled).  I submitted this as a minor bug since there is a simple workaround
(just use getOutputStream()).  

The problem can be demonstrated using the following servlet:


/**
 * To use this test:
 *
 * Hit the servlet with a browser.  "Sending Data" messages will be printed to
 * the brower window at a rate of one per second.  Hit the stop button on your
 * browser (causing checkError() to return true).  Repeat this until you get
 * a response where out.checkError() equals true before any data is sent
 * (it should only take about 5 tries).  This is the problem.
 *
 * From looking at the hashCodes, it looks like the PrintWriters are being
 * recycled and the checkError flag on these printWriters are never being
 * reset.
 *
 * Notice that this problem does not occur when using
 * response.getOutputStream().
 */
public class TestServlet extends HttpServlet {
  public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    // Simple workaround.  Servlet will work correctly if following line is
    // used instead.
    //PrintWriter out = new PrintWriter(response.getOutputStream());

    out.println("Entering Servlet:<BR>");
    out.println("<ul><li>out.hashCode(): " + out.hashCode() + "</li>");
    out.println("<li>out.checkError(): " + out.checkError() + "</li></ul>");
    while (!out.checkError())
    {
      try {Thread.currentThread().sleep(1000);} catch (Exception e) {}
      out.println("Sending Data<BR>");
    }
  }
}

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to