question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Datatable ConcurrentModificationException

See original GitHub issue

###JSF ConcurrentModificationException on datatable

We had an outage recently, and in the log of our application, we can see this exception. Looks like the data in a table is being modified while primefaces is sorting ¿How is this possible?

This is something that doesn’t happen frequently, it just happened once in a production enviroment. Also this same stack trace repeats like ten or more times in seconds.

I know that it is because some other thread is modifying the list, but I don’t understand why, because it is a simple datatable with a sorting and It happens occasionally.

05-Jul-2022 19:13:53.583 SEVERE [http-nio-8080-exec-746] com.sun.faces.application.view.FaceletViewHandlingStrategy.handleRenderException Error Rendering View[/pages/example.xhtml] java.util.ConcurrentModificationException at java.util.ArrayList.sort(ArrayList.java:1466) at java.util.Collections.sort(Collections.java:177) at org.primefaces.component.datatable.feature.SortFeature.singleSort(SortFeature.java:167) at org.primefaces.component.datatable.DataTableRenderer.preRender(DataTableRenderer.java:141) at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:93) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:949) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1912) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1908) at javax.faces.render.Renderer.encodeChildren(Renderer.java:176) at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:918) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1905) at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:638) at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) at javax.faces.component.UIForm.visitTree(UIForm.java:405) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1747) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1747) at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:423) at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:342) at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:65) at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:252) at org.omnifaces.context.OmniPartialViewContext.processPartial(OmniPartialViewContext.java:122) at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:1124) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1905) at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:465) at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:194) at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:151) at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:151) at org.omnifaces.viewhandler.OmniViewHandler.renderView(OmniViewHandler.java:155) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:126) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:223) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:671) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at ar.com.dux.jsf.filters.CacheFilter.doFilter(CacheFilter.java:27) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at ar.com.dux.jsf.filters.SecurityFilter.doFilter(SecurityFilter.java:84) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:89) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.omnifaces.filter.GzipResponseFilter.doFilter(GzipResponseFilter.java:183) at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:108) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:196) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:698) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:364) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:624) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:831) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1650) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)

Reproducer

No response

Expected behavior

No response

PrimeFaces edition

Community

PrimeFaces version

8

Theme

Avalon

JSF implementation

Mojarra

JSF version

2.3.9

Browser(s)

Chrome

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
fanstecommented, Jul 7, 2022

Edit: Damn, melloware was faster 😉

There are two possibe causes for that issue:

  1. Multiple threads working on the same list
  2. A single thread that modifies the list while iterating over it (e.g. counted for or foreach)

The second option should not be the cause here, as the stacktrace contains just a call to ArrayList.sort. I don’t think, that the JDK is faulty at that place.

The first option is more likely:

  • Simultanious AJAX requests - com.sun.faces.context.PartialViewContextImpl.processPartial should be an indication, that this happens during AJAX
  • Shared list due to wrong bean scope - e.g. session or even application
  • Correct bean scope, but the list comes from a shared source
0reactions
mellowarecommented, Jul 7, 2022

@marcelocastrillo you can try 1 of 2 solutions.

  1. Wrap your backing bean list Collections.synchronizedList
List<Object> objList = Collections.synchronizedList(new ArrayList<Object>());
  1. Try java.util.concurrent.CopyOnWriteArrayList https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/CopyOnWriteArrayList.html it’s expensive to modify, but wait-free to read.
Read more comments on GitHub >

github_iconTop Results From Across the Web

JSF ConcurrentModificationException on datatable
My 2 cents, could be a sequence of actions that lead to an update of the data table, when the table is still...
Read more >
Help with DataTable and java.util ...
Hi, i've a project in production moved in a new server from Tomcat 7.0.47 to Tomcat 8.5.35 (Jre updated from jre1.8.0_181 to jre1.8.0_192)....
Read more >
Solved: Concurrency / Synchronisation / ConcurrentModifica...
Concurrency / Synchronisation / ConcurrentModificationException ... But it doesn't work for updating ThingWorx DataTable concurrently.
Read more >
RE: ConcurrentModificationException on first load of portlets
hey everyone. I am seeing the following issue below under the following conditions in liferay 6.1.1: 1. remove all files from the temp...
Read more >
[#FACES-1541] ConcurrentModificationException on first load of ...
ConcurrentModificationException at java.util. ... I also noticed that putting the synchronized keyword on the getters that the dataTable is accessing will ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found