Bug 56010 - JspFactory.getPageContext with JspWriter.DEFAULT_BUFFER throws IllegalArgumentException
JspFactory.getPageContext with JspWriter.DEFAULT_BUFFER throws IllegalArgumen...
Product: Tomcat 7
Classification: Unclassified
Component: Jasper
PC Linux
: P2 normal (vote)
: ---
Assigned To: Tomcat Developers Mailing List
Depends on:
  Show dependency tree
Reported: 2014-01-15 03:34 UTC by Eugene Chung (TmaxSoft)
Modified: 2014-03-19 15:21 UTC (History)
0 users

Test Source (996 bytes, text/x-java)
2014-01-15 03:36 UTC, Eugene Chung (TmaxSoft)

Note You need to log in before you can comment on or make changes to this bug.
Description Eugene Chung (TmaxSoft) 2014-01-15 03:34:23 UTC
When a servlet calls JspFactory.getPageContext() with JspWriter.DEFAULT_BUFFER, Tomcat Japser throws IllegalArgumentException.

PageContext pageContext = JspFactory.getDefaultFactory().getPageContext(this, req, resp, null, false, JspWriter.DEFAULT_BUFFER, true);

java.lang.IllegalArgumentException: Buffer size <= 0

Based on the description of JspFactory.getPageContext(), if buffer size is JspWriter.DEFAULT_BUFFER(-1), PageContext must treat it as implementation default, which in case is org.apache.jasper.Constants#DEFAULT_BUFFER_SIZE(8192).

buffer - size of buffer in bytes, JspWriter.NO_BUFFER if no buffer, JspWriter.DEFAULT_BUFFER if implementation default.

from http://docs.oracle.com/javaee/7/api/javax/servlet/jsp/JspFactory.html#getPageContext(javax.servlet.Servlet, javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String, boolean, int, boolean)

Note that -Dorg.apache.jasper.runtime.JspFactoryImpl.USE_POOL=false should be specified.
Comment 1 Eugene Chung (TmaxSoft) 2014-01-15 03:36:57 UTC
Created attachment 31206 [details]
Test Source

I suggest that org.apache.jasper.runtime.PageContextImpl needs to check if buffer size is JspWriter.DEFAULT_BUFFER and adjust it to default.


        if (bufferSize == JspWriter.DEFAULT_BUFFER) {
            bufferSize = Constants.DEFAULT_BUFFER_SIZE;
        if (this.baseOut == null) {
            this.baseOut = new JspWriterImpl(response, bufferSize, autoFlush);
        } else {
            this.baseOut.init(response, bufferSize, autoFlush);
Comment 2 Mark Thomas 2014-01-16 14:24:38 UTC
Thanks for the report and the suggested fix.

I have committed the fix to 8.0.x along with a test case and it will be included in 8.0.0 onwards.

The same change has been applied to 7.0.x and it will be included in 7.0.51 onwards.
Comment 3 Konstantin Kolinko 2014-03-04 10:20:19 UTC
As far as I am reading, such value can only be used when calling the JspFactory.getPageContext() API directly. The buffer size that can be used in JSP configurations (in a page directive or in jsp-property-group) is either "none" (0) or is measured in kilobytes. (ch. JSP.1.10.1, JSP.3.3.10)

But I agree that this feature is a part of the API.

Proposed for 6.0.
Comment 4 Mark Thomas 2014-03-19 15:21:21 UTC
Fixed in 6.0.x for 6.0.40 onwards.