ConcurrentModificationException in vaadin-shared on karaf-4.2.x

I think I found a bug in Vaadin and wasn’t sure where to report it, so I’m posting it here.

I’m consistently getting the following error when starting my karaf 4.2.x instance with a vaadin 8.7.0 application:

2019-02-18T12:06:30,766 | ERROR | paxweb-config-1-thread-1 | shared                           | 131 - com.vaadin.shared - 8.7.0 | bundle com.vaadin.shared:8.7.0 (131)[com.vaadin.osgi.resources.impl.VaadinResourceTrackerComponent(7)]
 : The activate method has thrown an exception
java.util.ConcurrentModificationException: null
	at java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:719) ~[?:?]

	at java.util.LinkedHashMap$LinkedValueIterator.next(LinkedHashMap.java:747) ~[?:?]

	at com.vaadin.osgi.resources.impl.VaadinResourceTrackerComponent.activate(VaadinResourceTrackerComponent.java:207) ~[?:?]

	...

The activate method is currently as follows:

    protected void activate() throws NamespaceException {
       for (Delegate registration : resourceToRegistration.values()) {
            registerResource(registration);
       }
    }

Even though resourceToRegistration is a synchronized map, according to the java documentation:

It is imperative that the user manually synchronize on the returned map when iterating over any of its collection views

so I modified the above method as follows and it seems to work:

    protected void activate() throws NamespaceException {
        synchronized (resourceToRegistration) {
            for (Delegate registration : resourceToRegistration.values()) {
                registerResource(registration);
            }
        }
    }

I think there are other places in that class where the same map and other maps are accessed in a similar way. But the above is enough to fix the bootstrap in karaf.

I wasn’t getting this error with karaf 4.1.x but when I upgraded to 4.2.x it happens every time when my application boots, or rather, fails to boot.

Regards,
Carlos