Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SendError function not throwing IllegalStateException

 
Adri Smith
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am surprise that this code is working well without throwing any exception:

public class errorServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();

out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.println("Hello world");
out.println(" </BODY>");
out.println("</HTML>");

response.flushBuffer();
response.sendError(HttpServletResponse.SC_NOT_FOUND);
out.flush();
out.close();
}
}

I think this should raise the exception IllegalStateException because the method flushBuffer commits the response.

If we take a look in the API we can see this:

flushbuffer => A call to this method automatically commits the response
sendError => If the response has already been committed, this method throws an IllegalStateException

So why is this not happening ?

I am using Tomcat 5.0. is it Tomcat not compliant or I am misunderstandign something ?

thanks in advance,
ADri
 
Sivasundaram Umapathy
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your servlet on resin produces "java.lang.IllegalStateException: forward() not allowed after buffer has committed." where as it runs well on Tomcat.

So this may be an instance of one more tomcat issue.

Infact, I suggest you to make a note of these violations and report to tomcat mailing lists(Offcourse check the bug database before to ensure that it is not reported already)
 
Adri Smith
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx to gave me your opinion about this point.

This help to make me more confindent I am not missing some points.

I will try after taking the exam to contact Tomcat if this is not reported yet.

Adri
 
Sivasundaram Umapathy
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the best with your exam preparation
 
Adri Smith
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot

You are helping me very much in making things clear

I wish you all the best

This forum is wonderful !

Adri
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic