You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Volodymyr Siedlecki (Jira)" <de...@myfaces.apache.org> on 2022/12/09 19:56:00 UTC

[jira] [Created] (MYFACES-4527) jakarta.servlet.ServletException: setBufferSize() called after first write to Output Stream/Writer

Volodymyr Siedlecki created MYFACES-4527:
--------------------------------------------

             Summary:  jakarta.servlet.ServletException: setBufferSize() called after first write to Output Stream/Writer
                 Key: MYFACES-4527
                 URL: https://issues.apache.org/jira/browse/MYFACES-4527
             Project: MyFaces Core
          Issue Type: Improvement
            Reporter: Volodymyr Siedlecki


This was discovered in TCK: Spec1135IT. 

Test: https://github.com/jakartaee/faces/blob/4.0.1/tck/faces23/systemEvent/src/test/java/ee/jakarta/tck/faces/test/servlet40/systemevent/Spec1135IT.java#L71

App Code: https://github.com/jakartaee/faces/tree/4.0.1/tck/faces23/systemEvent/src/main

The app uses has a method which is invoked before the view has started to be rendered. This write to the response before a response writer has been created by MyFaces.  This causes the ServletException in the title. By the time MyFaces is ready create the response writer and set the buffer size, it's already been written to. 

Per the Servlet Spec: 
setBufferSize throws an IllegalStateException  if this method is called after content has been written

https://jakarta.ee/specifications/servlet/6.0/apidocs/jakarta.servlet/jakarta/servlet/servletresponse#setBufferSize(int)

Solution seems to be to create a response writer if none exist. 
https://github.com/apache/myfaces/blob/db37634747e11ba24216ea384c33ad3c6d2cefcb/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java#L1747



--
This message was sent by Atlassian Jira
(v8.20.10#820010)