java.util.ConcurrentModificationException (UidlWriter.write)

Hello Vaadin Experts,

I have a strange error that we have been seeing in our Vaadin application (7.5.8, Tomcat 8.0.26, Polling mode) on a particular screen. We can reproduce this error every time. After a couple of actions in the user interface, we get the following error:


2015-11-02 10:44:53,993 CST ERROR [DXOPUIServlet:service()]
 - java.util.ConcurrentModificationException:
at java.util.HashMap$HashIterator.nextNode(Unknown Source)
at java.util.HashMap$ Source)
at com.vaadin.server.communication.UidlWriter.write(
at com.vaadin.server.communication.UidlRequestHandler.writeUidl(
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(
at com.vaadin.server.VaadinService.handleRequest(
at com.vaadin.server.VaadinServlet.service(
at com.dmb.ui.DXOPUIServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.apache.tomcat.websocket.server.WsFilter.doFilter(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.apache.catalina.core.StandardWrapperValve.invoke(
at org.apache.catalina.core.StandardContextValve.invoke(
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(
at org.apache.catalina.core.StandardHostValve.invoke(
at org.apache.catalina.valves.ErrorReportValve.invoke(
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(
at org.apache.catalina.core.StandardEngineValve.invoke(
at org.apache.catalina.connector.CoyoteAdapter.service(
at org.apache.coyote.http11.AbstractHttp11Processor.process(
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$ Source)
at org.apache.tomcat.util.threads.TaskThread$
at Source)

Do you guys have any ideas how we can debug this further, or what might be causing this behavior?

Hi Cboyd,

I find your
at com.dmb.ui.DXOPUIServlet.service(
somewhat suspect.

From the HttpServlet documentation at :
There’s almost no reason to override the service method. service handles standard HTTP requests by dispatching them to the handler methods for each HTTP request type (the doXXX methods listed above).

So I wonder whether you made a mistake in that method, for example calling super() twice or not
locking access to resources where due.

Here is our service implementation:

    protected void service( HttpServletRequest request, HttpServletResponse response )
        throws ServletException, IOException
        VAADIN_COMM_COUNT_MAP.put( new Object(), 0 );
            NDC.push( CLASS_NAME + ":service()" );
            super.service( request, response );
            logger.debug( "Service Request: " + request.getQueryString() );
        catch ( Exception exc )
            logger.error( exc );

I actually found that a Vaadin add-on, LazyLoadWrapper, was causing this behavior. After taking the add-on out, the behavior went away.

I do have to question why a
isn’t being used in UidlWriter though.

UidlWriter is designed to only be used when the VaadinSession is locked by the current thread. Chaning it to use ConcurrentHashMap would just make the issue appear in some other part that is also designed for single threaded use.

Please see!/thread/11502121
for more details about this kind of problem.