ConcurrentModificationException when using the CustomField add-on

Hi all,

I installed the CustomField add-on (version 0.9.0) and followed the examples from the source code at http://code.google.com/p/customfield/source/browse/trunk/src/org/vaadin/addon/customfield/demo/NestedPersonForm.java.

It all works fine until I call setVisibleItemProperties() on my main form. If the list of visible items contains my CustomField, I get the following exception:


java.util.ConcurrentModificationException
	at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:761)
	at java.util.LinkedList$ListItr.next(LinkedList.java:696)
	at com.vaadin.ui.CssLayout.paintContent(CssLayout.java:185)
	at com.vaadin.ui.AbstractComponent.paint(AbstractComponent.java:754)
	at com.vaadin.ui.Form.paintContent(Form.java:207)
	at com.vaadin.ui.AbstractComponent.paint(AbstractComponent.java:754)
	at com.vaadin.ui.CssLayout.paintContent(CssLayout.java:187)
	at com.vaadin.ui.AbstractComponent.paint(AbstractComponent.java:754)
	at com.vaadin.ui.CssLayout.paintContent(CssLayout.java:187)
	at com.vaadin.ui.AbstractComponent.paint(AbstractComponent.java:754)
	at com.vaadin.ui.Panel.paintContent(Panel.java:255)
	at com.vaadin.ui.Window.paintContent(Window.java:623)
	at com.vaadin.ui.AbstractComponent.paint(AbstractComponent.java:754)
	at com.vaadin.ui.Window.paintContent(Window.java:646)
	at com.vaadin.ui.AbstractComponent.paint(AbstractComponent.java:754)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.writeUidlResponce(AbstractCommunicationManager.java:952)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.paintAfterVariableChanges(AbstractCommunicationManager.java:839)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:765)
	at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:296)
	at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:483)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
	at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
	at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
	at org.mortbay.jetty.Server.handle(Server.java:326)
	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
	at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943)
	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

If I remove the CustomField property, everything shows up. However, since it’s not part of the visible item properties, calling “discard()” on my main form doesn’t call “discard()” on my CustomField.

Does anybody have an idea on what’s going on here?

Thanks,

Mike

Where/when are you calling setVisibleItemProperties()?

I assume you are trying to do this with the EmbeddedForm in the example, nesting the sub-form fields directly in the top-level form layout. There are some limitations and complications in the sample EmbeddedForm class with respect to how fields are added to and removed from the top-level form, so I would not be surprised if this is the cause.

I tried different approaches and places to call setVisibleItemProperties().

  1. Passing a list of visible item properties to the setItemDataSource() method.
  2. Calling setItemDataSource() first, then setVisibleItemProperties().
  3. Calling setVisibleItemProperties() first, then setItemDataSource().

Yes you’re assumption is correct in regards to the EmbeddedForm and how I use it. I literally replicated what I found in the source code mentioned in my previous post.

I’ll investigate further and if I can’t solve it, might have to use a different approach. Do you have any suggestions on an alternative to the CustomField add-on?

The complications are related to how the Form adds and removes its fields to its layout, and how it interacts with EmbeddedForm. I have not looked into it for a long time, but I do remember it was tricky.

A cleaner alternative would be to have the Item expose also the nested contents directly as item Properties. With Vaadin 6.6.0.pre1 and later, you can add nested bean properties to a Bean[Item]
Container or a BeanItem/PropertySetItem - e.g. myPersonContainer.addNestedContainerProperty("address.street") or myItem.addItemProperty(new NestedMethodProperty(myItem.getBean(), "address.street"));

Thanks, I read about the addNestedContainerProperty() method earlier this morning. I’m trying to upgrade right now, but having some troubles with compiling my widgetsets with GWT 2.3.0. I’ll post that in a separate thread if I can’t resolve it ;).