Mantis - Resin
Viewing Issue Advanced Details
4964 major always 02-27-12 13:53 06-15-12 15:41
mcamca  
ferg  
normal  
closed 4.0.25  
fixed  
none    
none 4.0.29  
0004964: ClassCastException from PageContextImpl.popBody() after call to pushBody(Writer)
com.caucho.jsp.PageContextImpl implements 2 versions of the pushBody() method:

BodyContent pushBody();
JspWriter pushBody(Writer writer);

However, its implementation of JspContext.popBody() performs a cast that assumes the no-args version of pushBody() was called. If the second form of pushBody() was called, then popBody() will fail with an exception like this:

java.lang.ClassCastException: com.caucho.jsp.StreamJspWriter cannot be cast to com.caucho.jsp.BodyContentImpl
    at com.caucho.jsp.PageContextImpl.popBody(PageContextImpl.java:683)
    [...]

I have observed this behavior in Resin 3.1.9 and 4.0.25. The following code change made the problem go away for me, but I'm not sufficiently familiar with Resin's code base to know if it's the best, or even a good, solution.

Index: modules/resin/src/com/caucho/jsp/PageContextImpl.java
===================================================================
--- modules/resin/src/com/caucho/jsp/PageContextImpl.java (revision 5126)
+++ modules/resin/src/com/caucho/jsp/PageContextImpl.java (working copy)
@@ -673,8 +673,7 @@
    */
   public JspWriter popBody()
   {
- BodyContentImpl bodyOut = (BodyContentImpl) _out;
- _out = bodyOut.getEnclosingWriter();
+ _out = ((AbstractJspWriter) _out).getEnclosingWriter();
 
     try {
       _bodyResponseStream.flushBuffer();
Index: modules/resin/src/com/caucho/jsp/StreamJspWriter.java
===================================================================
--- modules/resin/src/com/caucho/jsp/StreamJspWriter.java (revision 5126)
+++ modules/resin/src/com/caucho/jsp/StreamJspWriter.java (working copy)
@@ -41,8 +41,6 @@
   private Writer _writer;
   
   private JspPrintWriter _printWriter;
-
- private JspWriter _parent;
   
   // the page context
   private PageContextImpl _pageContext;
@@ -63,7 +61,7 @@
    */
   void init(JspWriter parent, Writer writer)
   {
- _parent = parent;
+ setParent(parent);
     _writer = writer;
     _isClosed = false;
   }

Notes
(0005860)
ferg   
06-15-12 15:41   
jsp/162h