tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bucknam, Brian" <Brian.Buck...@webgain.com>
Subject Jasper Compiler -- when things go really wrong
Date Tue, 19 Dec 2000 19:34:39 GMT
It's a long story, but I'm working on a project where Jasper 3.x is embedded
inside a servlet, which can then be deployed to the container of our
customer's choice.  The servlet uses JSP files as templates, which is where
Jasper comes in.

In this type of environment, sometimes thing can go really wrong, and the
compiled JSP might, in some cases, fail to get a JspFactory, PageContext, or
JspWriter.

Here is a much-snipped version of what JspParseEventListener (in 3.2 and
4.0) generates for the _jspService() method:
------------------------------------------------
JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
JspWriter out = null;
try {
    _jspxFactory = JspFactory.getDefaultFactory();
    pageContext = _jspxFactory.getPageContext(this, request, response,
          "", true, 4096, true);

    out = pageContext.getOut();

    // HTML stuff here
        out.write("...my happy JSP page...");
    // end
} catch (Exception ex) {
    if (out.getBufferSize() != 0)
        out.clearBuffer();
    pageContext.handlePageException(ex);
} finally {
    out.flush();
    _jspxFactory.releasePageContext(pageContext);
}
------------------------------------------------

If any of _jspxFactory, pageContext, or out fail to be created, the catch{}
and finally{} clauses just throw NPE's.

I would propose that the catch{} and finally{} should generated as following
instead:
------------------------------------------------
} catch (Exception ex) {
    if (out != null && out.getBufferSize() != 0)
        out.clearBuffer();
    if (pageContext != null) pageContext.handlePageException(ex);
} finally {
    if (out != null) out.flush();
    if (_jspxFactory != null)
        _jspxFactory.releasePageContext(pageContext);
}
------------------------------------------------

These seem to me like non-functionality-impacting changes.

If this seems right, I will generate patch files if requested.

Thanks,
Brian

Brian Bucknam
WebGain, Inc.
brian.bucknam@webgain.com

Mime
View raw message