java.lang.IllegalStateException: getOutputStream() has already been called for this response

1,711 views
Skip to first unread message

Ralf

unread,
Aug 18, 2010, 10:35:30 AM8/18/10
to javamelody
Hi,

in a web application using Spring MVC with javamelody enabled i am
trying to render my error messages with an
org.springframework.web.servlet.HandlerExceptionResolver. In the
moment, the exception resolver is called, i can't ensure, that nothing
has been written onto the response stream. That's why i call first
call response.reset() and then render my error view (in this case via
Freemarker).

In some cases i now get an java.lang.IllegalStateException:
getOutputStream() has already been called for this response from
net.bull.javamelody.FilterServletResponseWrapper.getWriter(FilterServletResponseWrapper.java:
117). Why is it prohibited to call getWriter() twice? Should the
writer's state no be resetted if possible in the reset-Method?

Thanks for your advice,
Ralf

evernat

unread,
Aug 20, 2010, 12:13:34 PM8/20/10
to javamelody
Hi Ralf,

Good catch.

I have committed a fix in trunk of svn to reset the writer and the
stream at the end of the reset() method of
FilterServletResponseWrapper.
Revision 1179: http://code.google.com/p/javamelody/source/detail?r=1179
With the fix, the getWriter() method of FilterServletResponseWrapper
will not throw the exception "getOutputStream() has already been
called for this response", after a successfull call to the reset()
method.

But the reset() method may also throw an IllegalStateException, if you
have already written too much in the buffer, given its javadoc in
javax.servlet.ServletResponse: "If the response has been committed,
this [reset()] method throws an IllegalStateException."


If you wish, you can use the new build which I have just made from the
current trunk:
http://javamelody.googlecode.com/files/javamelody-20100820.jar

Note that it is a jar file from the current trunk and so it is an
intermediate beta for the next release, and that it changes how
debbuging logs are managed as said in:
http://code.google.com/p/javamelody/wiki/ReleaseNotes

bye, Emeric
Reply all
Reply to author
Forward
0 new messages