Tomcat: No modifications are allowed to a locked ParameterMap

8.7k views Asked by At

Got sick of this annoying error:

java.lang.IllegalStateException: No modifications are allowed to a locked ParameterMap
at org.apache.catalina.util.ParameterMap.put(ParameterMap.java:164)
at org.springframework.data.rest.webmvc.RestRepositoryEntityController.getParametersForPostAction(RestRepositoryEntityController.java:182)
at org.springframework.data.rest.webmvc.RestRepositoryEntityController.performPostAction(RestRepositoryEntityController.java:158)
at org.springframework.data.rest.webmvc.RestRepositoryEntityController.performOneArgumentPostRepositoryAction(RestRepositoryEntityController.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:747)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:485)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:410)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:337)

I'm getting this after trying to access some rest resources. Everything works fine on production, so I suppose there are some tomcat problems on my local pc. Spend two hours trying to find answers but didn't succeed.

Did anyone occurred with same error? Need help!

3

There are 3 answers

0
noyal_asok On

It might be because you are assigning request.getParameterMap() any of the variable. Instead of that try using

Map<String, String[]> map = new HashMap<>(request.getParameterMap());

which will only create a copy of it.

Sometimes this may solve your problem

0
John Korch On

Did not find any reason of such behavior. The only thing that helped - I changed tomcat versions from 7.0.68 to 7.0.61

0
Nati On

If you have a code in your servelet like this

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // more java code 
            request.getParameterMap().clear(); // remove this
         // more java code 
   }

This is what most likely caused it. (in my case after i debugged my code)

It will automatically clear the input fields of your form or input when you submit it to your servelet. Since the response has already been committed or sent to the client, so you won't be able to modify the query parameters of the servelet that you sent it to. i.e( doGet, doPost, servelet or in the jsp itself)