Bug 63350

Summary: JSP out.print() does not rethrow IOException
Product: Tomcat 9 Reporter: pmd1nh-rm
Component: JasperAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED INVALID    
Severity: normal    
Priority: P2    
Version: 9.0.19   
Target Milestone: -----   
Hardware: PC   
OS: Mac OS X 10.1   

Description pmd1nh-rm 2019-04-15 21:03:02 UTC
Hi,

The out.print() does not rethrow IOException back to the caller JSP.  While the PrintWriter APIs do not throw any IOException, the JSPWriter (which is the type for the implicit "out") should throw the IOException.

Simple JSP to recreate the issue:

<%
    System.out.println("JSP start");
    try {
        for (int i=0 ; i<43490 ; i++) {
            out.print("xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy");
        }
        out.print("END_OF_DATA");
    }
    catch(java.io.IOException e) {
        System.out.println("caught a IOException !!!");
        e.printStackTrace(System.out);
        throw e;
    }
    System.out.println("JSP end");
 %>

While request to the JSP, immediately cancel the connection (by ctrl-C).  That will cause a broken pipe connection and result in the IOException.

The JSPWriterImpl's "out" is back by the ServletResponse.getWriter() which is the PrintWriter. 


private void initOut() throws IOException {
            if (out == null) {
                out = response.getWriter();
            }
}

So I think this PrintWriter has swallowed the IOException.

Thanks,
Comment 1 Remy Maucherat 2019-04-23 08:12:48 UTC
Please use the user list to discuss the behavior if you'd like. The Servlet's writer is indeed a PrintWriter, it sets error flags but does not throw IOE exceptions.