Bug 63350 - JSP out.print() does not rethrow IOException
Summary: JSP out.print() does not rethrow IOException
Status: RESOLVED INVALID
Alias: None
Product: Tomcat 9
Classification: Unclassified
Component: Jasper (show other bugs)
Version: 9.0.19
Hardware: PC Mac OS X 10.1
: P2 normal (vote)
Target Milestone: -----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-15 21:03 UTC by pmd1nh-rm
Modified: 2019-04-23 08:12 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.