java.lang.IllegalStateException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • The fix for SPR-11705 does not work with Tomcat 8.0.21 {code} public void sendError(int sc, String msg) throws IOException { copyBodyToResponse(); super.sendError(sc, msg); this.statusCode = sc; } {code} When {{copyBodyToResponse()}} is called, Tomcat considers the response committed. Then, when {{sendError}} is called, Tomcat throws {code} org.glassfish.jersey.server.ServerRuntime$Responder - Error while closing the output stream in order to commit response. java.lang.IllegalStateException: Cannot call sendError() after the response has been committed at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:462) at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:120) at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:120) at org.springframework.web.util.ContentCachingResponseWrapper.sendError(ContentCachingResponseWrapper.java:83) {code} Tomcat considers the response committed because contentLength is more than 0, and it is the same as contentWritten. From org/apache/catalina/connector/Response.java: {code} public boolean isAppCommitted() { return (this.appCommitted || isCommitted() || isSuspended() || ((getContentLength() > 0) && (getContentWritten() >= getContentLength()))); } {code} I propose that whenever content length > 0, sendError should not be called. My current workaround: {code} public class BackendContentCachingResponseWrapper extends ContentCachingResponseWrapper { public BackendContentCachingResponseWrapper(HttpServletResponse response) { super(response); } @Override public void sendError(int sc, String msg) throws IOException { try { super.sendError(sc, msg); } catch (IllegalStateException e) { // ignore } } } {code}
    via by Victor Lyuboslavsky,
  • The fix for SPR-11705 does not work with Tomcat 8.0.21 {code} public void sendError(int sc, String msg) throws IOException { copyBodyToResponse(); super.sendError(sc, msg); this.statusCode = sc; } {code} When {{copyBodyToResponse()}} is called, Tomcat considers the response committed. Then, when {{sendError}} is called, Tomcat throws {code} org.glassfish.jersey.server.ServerRuntime$Responder - Error while closing the output stream in order to commit response. java.lang.IllegalStateException: Cannot call sendError() after the response has been committed at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:462) at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:120) at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:120) at org.springframework.web.util.ContentCachingResponseWrapper.sendError(ContentCachingResponseWrapper.java:83) {code} Tomcat considers the response committed because contentLength is more than 0, and it is the same as contentWritten. From org/apache/catalina/connector/Response.java: {code} public boolean isAppCommitted() { return (this.appCommitted || isCommitted() || isSuspended() || ((getContentLength() > 0) && (getContentWritten() >= getContentLength()))); } {code} I propose that whenever content length > 0, sendError should not be called. My current workaround: {code} public class BackendContentCachingResponseWrapper extends ContentCachingResponseWrapper { public BackendContentCachingResponseWrapper(HttpServletResponse response) { super(response); } @Override public void sendError(int sc, String msg) throws IOException { try { super.sendError(sc, msg); } catch (IllegalStateException e) { // ignore } } } {code}
    via by Victor Lyuboslavsky,
  • Tomcat CSRF Filter configuration
    via Stack Overflow by Nilesh
    ,
    • java.lang.IllegalStateException: Cannot call sendError() after the response has been committed at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:462) at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:120) at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:120) at org.springframework.web.util.ContentCachingResponseWrapper.sendError(ContentCachingResponseWrapper.java:83)

    Users with the same issue

    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    29 more bugmates