[
https://issues.apache.org/jira/browse/MYFACES-4527?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17709431#comment-17709431
]
Volodymyr Siedlecki commented on MYFACES-4527:
----------------------------------------------
https://github.com/apache/myfaces/pull/431/commits
> 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
> Affects Versions: 2.2.15, 2.3.10, 2.3-next-M7, 4.0.0-RC2
> Reporter: Volodymyr Siedlecki
> Assignee: Volodymyr Siedlecki
> Priority: Major
> Fix For: 2.3.11, 3.0.3, 2.3-next-M8, 4.0.0-RC3
>
> Attachments: test-faces23-systemEvent.war
>
>
> 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/master/tck/faces23/systemEvent/src/main
> ( App was updated, using master branch for latest code)
> {code:java}
> public void pre(ComponentSystemEvent event) throws IOException {
>
> facesContext.setResponseWriter(facesContext.getRenderKit().createResponseWriter(externalContext.getResponseOutputWriter(),
> "text/html", "UTF-8"));
> facesContext.getResponseWriter().write("<!-- pre -->");
> }
> {code}
> The app uses has a method ("pre") which is invoked before the view has
> started to be rendered. This method creates a response writer of its own, and
> then it writes a block of text. Then, by the time MyFaces is ready to create
> the response writer and set the buffer size, it's already been written to.
> Thus the ServletException occurs.
> 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)