Nikita,

I'm not sure if your code lines are just written request but they are really
response like in your final email, but here goes.

I haven't written servlets themselves in a really long time.  Too much time
wasted redoing all the fancy stuff things like Spring and Struts already do
for me.  What I seem to remember is that this would make sense. 

flushBuffer() is used to periodically flush what is left in the response
buffer that should go to the browser.  If you haven't gotten the writer yet
then the structures have not been initialized yet and would be null.  

If I remember correctly the flushBuffer() is called automatically at the end
of a doGet/doPost call so unless you are trying to push partial content to
the browser because you have a huge web page to display (100's+ of database
records usually resulting in an HTML files of 2K+) then there isn't much
reason to call it. The best I/O is generally perceived with less calls to
flushBuffer() but the more in the buffer the more memory that is used.
That's one of those performance type of things I won't get into.

Chris Berthold
IT Systems Analyst
Commercial Refrigerator Door Company
941 . 371 . 8110 x 205

-----Original Message-----
From: Nikita Tovstoles [mailto:[EMAIL PROTECTED] 
Sent: Thursday, May 04, 2006 11:35 AM
To: Tomcat Users List
Subject: Re: NPE: outputStream is null in InternalOutputBuffer - why?

Answering my own question, and asking another:

I have this line in finally{} of  Servlet.processRequest():

response.flushBuffer(); //if response.getWriter() was never called, then 
this method call will result in NPE.

Is this proper behavior or should I file a bug report?


Nikita Tovstoles wrote:
> Hi,
>
> I am load testing a webapp running on Tomcat 5.5.12 (windoze). Once in 
> a while I see the following in Tomcat's log:
>
> SEVERE: Servlet.service() for servlet StatusServlet threw exception
> java.lang.NullPointerException
>    at 
>
org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputB
uffer.java:747) 
>
>    at 
> org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:403)
>    at 
>
org.apache.coyote.http11.InternalOutputBuffer.flush(InternalOutputBuffer.jav
a:305) 
>
>    at 
> org.apache.coyote.http11.Http11Processor.action(Http11Processor.java:990)
>    at org.apache.coyote.Response.action(Response.java:182)
>    at 
> org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:322)
>    at 
> org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:293)
>    at 
> org.apache.catalina.connector.Response.flushBuffer(Response.java:544)
>    at 
>
org.apache.catalina.connector.ResponseFacade.flushBuffer(ResponseFacade.java
:276) 
>
>    at com.eviltwin.servermanager.BaseServlet.processRequest(Unknown 
> Source)
>    at 
> com.eviltwin.servermanager.envserver.StatusServlet.processRequest(Unknown 
> Source)
>    at com.eviltwin.servermanager.BaseServlet.doGet(Unknown Source)
>    at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
>    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>    at 
>
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:252) 
>
>    at 
>
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:173) 
>
>    at 
>
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:213) 
>
>    at 
>
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:178) 
>
>    at 
>
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126
) 
>
>    at 
>
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105
) 
>
>    at 
>
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
:107) 
>
>    at 
>
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) 
>
>    at 
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)

>
>    at 
>
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processC
onnection(Http11BaseProtocol.java:663) 
>
>    at 
>
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.jav
a:527) 
>
>    at 
>
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWo
rkerThread.java:80) 
>
>    at 
>
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
a:684) 
>
>    at java.lang.Thread.run(Thread.java:595)
>
> Looking at Tomcat's source code, it appears outputStream is null in 
> InternalOutputBuffer. I have the following code that runs once per 
> request:
>
> processRequest()
> {
>    ///other work
>    finally{
>        request.getWriter().println(someString); //can be up to 200-300 
> chars long
>        request.getWriter().close();
>    }
> }
> Could someone please explain:
>
> -Why is this NPE happening?
> - Is it occurring during println() or close() (or somewhere else)?
> -Any workaround / solution?
>
> thanks a lot
>
> -nikita
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to