You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Joel Roth-Nater <ro...@quoininc.com> on 2002/06/16 09:08:52 UTC

ClassCastException in PageContextImpl

(longish, please read if you're familiar with Jasper sources)

I'm using Jasper which comes packaged with JBoss 3.0. One of the JSPs
has the following code:

BodyContent bc = pageContext.pushBody();
request.getRequestDispatcher(jspName).forward(request, response);
pageContext.popBody();
wc.writeOut(new FileWriter(...));

I am using this to generate a bunch of files on disk. At the bottom of
the including page, I get the following error:

java.lang.ClassCastException: org.apache.jasper.runtime.BodyContentImpl
        at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:174)
        at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:198)
        at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:193)
        at org.apache.jsp.generate$jsp._jspService(generate$jsp.java:552)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
<snip>


This is the cleanup code at the bottom of the JSP (generate$jsp.java):

      } catch (Throwable t) {
        if (out != null && out.getBufferSize() != 0)
          out.clearBuffer();
        if (pageContext != null) pageContext.handlePageException(t);
      } finally {
552:    if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
      }


... and this is the Jasper code where it happens (PageContextImpl.java):

    public void release() {
        out = baseOut;
        try {
            if (isIncluded) {
174:            ((JspWriterImpl)out).flushBuffer();
                        // push it into the including jspWriter
            } else {
                out.flush();
            }
        } catch (IOException ex) {
            loghelper.log("Internal error flushing the buffer in release()");
        }


It seems that after the popBody() in the JSP, out is no longer of
class JspWriterImpl with makes the cast fail. To be sure, my use of
the BodyContent is somewhat creative, but I'm not aware that I'm
breaking any J2EE contract. Also, my code works just fine under
WebLogic. Would it make sense to check instanceof JspWriterImpl on
line 173?

Or am I missing something?

Any hint is appreciated

-- Joel


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Trying again: ClassCastException in PageContextImpl

Posted by Remy Maucherat <re...@apache.org>.
Joel Roth-Nater wrote:
> I'm re-posting this because I believe there's a bug here and I haven't
> got any responses:

This code got cleaned up in Jasper 2, so this should work better.
It is unlikely this would get ported to Jasper 1, though.

Remy


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Trying again: ClassCastException in PageContextImpl

Posted by Joel Roth-Nater <ro...@quoininc.com>.
I'm re-posting this because I believe there's a bug here and I haven't
got any responses:


On Sun, 16 Jun 2002, Joel Roth-Nater wrote:

> (longish, please read if you're familiar with Jasper sources)
> 
> I'm using Jasper which comes packaged with JBoss 3.0. One of the JSPs
> has the following code:
> 
> BodyContent bc = pageContext.pushBody();
> request.getRequestDispatcher(jspName).forward(request, response);
> pageContext.popBody();
> wc.writeOut(new FileWriter(...));
> 
> I am using this to generate a bunch of files on disk. At the bottom of
> the including page, I get the following error:
> 
> java.lang.ClassCastException: org.apache.jasper.runtime.BodyContentImpl
>         at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:174)
>         at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:198)
>         at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:193)
>         at org.apache.jsp.generate$jsp._jspService(generate$jsp.java:552)
>         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
> <snip>
> 
> 
> This is the cleanup code at the bottom of the JSP (generate$jsp.java):
> 
>       } catch (Throwable t) {
>         if (out != null && out.getBufferSize() != 0)
>           out.clearBuffer();
>         if (pageContext != null) pageContext.handlePageException(t);
>       } finally {
> 552:    if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
>       }
> 
> 
> ... and this is the Jasper code where it happens (PageContextImpl.java):
> 
>     public void release() {
>         out = baseOut;
>         try {
>             if (isIncluded) {
> 174:            ((JspWriterImpl)out).flushBuffer();
>                         // push it into the including jspWriter
>             } else {
>                 out.flush();
>             }
>         } catch (IOException ex) {
>             loghelper.log("Internal error flushing the buffer in release()");
>         }
> 
> 
> It seems that after the popBody() in the JSP, out is no longer of
> class JspWriterImpl with makes the cast fail. To be sure, my use of
> the BodyContent is somewhat creative, but I'm not aware that I'm
> breaking any J2EE contract. Also, my code works just fine under
> WebLogic. Would it make sense to check instanceof JspWriterImpl on
> line 173?
> 
> Or am I missing something?
> 
> Any hint is appreciated
> 
> -- Joel
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>