Bug 56010

Summary: JspFactory.getPageContext with JspWriter.DEFAULT_BUFFER throws IllegalArgumentException
Product: Tomcat 7 Reporter: Eugene Chung (TmaxSoft) <bluewolf.chung>
Component: JasperAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: trunk   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: Test Source

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
	org.apache.jasper.runtime.JspWriterImpl.<init>(JspWriterImpl.java:81)
	org.apache.jasper.runtime.PageContextImpl._initialize(PageContextImpl.java:154)
	org.apache.jasper.runtime.PageContextImpl.initialize(PageContextImpl.java:125)
	org.apache.jasper.runtime.JspFactoryImpl.internalGetPageContext(JspFactoryImpl.java:112)
	org.apache.jasper.runtime.JspFactoryImpl.getPageContext(JspFactoryImpl.java:65)
	dvt.jsp.jaspertest.JspFactoryTestServlet.doGet(JspFactoryTestServlet.java:21)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)



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.

org.apache.jasper.runtime.PageContextImpl#initialize(..)


        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.