Bug 56223 - ServletContext#setInitParameter(..) does not throw IllegalStateException after it's been initialized
ServletContext#setInitParameter(..) does not throw IllegalStateException afte...
Status: RESOLVED FIXED
Product: Tomcat 8
Classification: Unclassified
Component: Specification APIs
8.0.3
PC All
: P2 normal (vote)
: ----
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2014-03-06 02:15 UTC by Sotirios Delimanolis
Modified: 2014-03-06 16:21 UTC (History)
0 users



Attachments
.war with single Servlet (1.28 KB, application/octet-stream)
2014-03-06 02:15 UTC, Sotirios Delimanolis
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sotirios Delimanolis 2014-03-06 02:15:48 UTC
Created attachment 31369 [details]
.war with single Servlet

The Java EE javadoc for ServletContext#setInitParameter(String, String), here: http://docs.oracle.com/javaee/7/api/javax/servlet/ServletContext.html#setInitParameter(java.lang.String, java.lang.String), states that the method should throw an IllegalStateException if the ServletContext has already been initialized.

Once a Servlet is ready to handle requests, the ServletContext must have been initialized. However, no exception is thrown if you try to invoke the method in an HttpServlet's doGet(..).

Steps to reproduce:

1) Add an HttpServlet that invokes the method in its doGet(..) method

@WebServlet(urlPatterns = "/init")
public class InitParameterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

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

		ServletContext context = getServletContext();
		context.setInitParameter("init-param", "value");

	}
}

2) Send an HTTP GET request to (the appropriate) 'http://localhost:8080/context/init`.

Actual results: No exception is thrown. Server sends back 200 OK.

Expected results: An exception should have been thrown. Server should have sent back 500 status code.

Tomcat 8.0.3 (and 7.0.42) and Windows 7

Additional information: You can also try calling, for example, the addFilter(..) method which will fail stating that the ServletContext is already initialized.
Comment 1 Mark Thomas 2014-03-06 16:21:38 UTC
Thanks for the report.

This has been fixed in 7.0.x for 7.0.53 onwards and in 8.0.x for 8.0.4 onwards.