Community
Participate
Working Groups
Eclipse Version: 4.2.0 Build id: I20120126-1300 (EMF 2.8) I apologize in advance as I'm not a strong EMF user. I've hit an NPE with E4 and EMF (relevant stack trace below) where we attempt to add a notifier to our root MApplication object as follows: ((Notifier) uiRoot).eAdapters().add(uiEventPublisher); The NPE arises as our MApplication's toolBarContributions feature (a list of MToolBarContribution) has had a "null" entry: [org.eclipse.e4.ui.model.application.ui.menu.impl.ToolBarContributionImpl@6164bd1e (elementId: null, tags: null, contributorURI: null) (widget: null, renderer: null, toBeRendered: true, onTop: false, visible: true, containerData: null, accessibilityPhrase: null) (parentId: mail.view, positionInParent: after=additions), null] I haven't been able to trace how/why/where this null has been added, and although it doesn't really make sense for E4, it might make sense for other situations. I think the code in EContentAdapter.setTarget(EObject) should have a guard within the loop: /** * Handles installation of the adapter on an EObject * by adding the adapter to each of the directly contained objects. */ protected void setTarget(EObject target) { basicSetTarget(target); for (Iterator<? extends Notifier> i = resolve() ? target.eContents().iterator() : ((InternalEList<? extends Notifier>)target.eContents()).basicIterator(); i.hasNext(); ) { Notifier notifier = i.next(); if(notifier != null) { addAdapter(notifier); } } } Daemon Thread [Thread-1] (Suspended (exception NullPointerException)) UIEventPublisher(EContentAdapter).addAdapter(Notifier) line: 352 UIEventPublisher(EContentAdapter).setTarget(EObject) line: 225 UIEventPublisher(EContentAdapter).setTarget(Notifier) line: 188 MinimalEObjectImpl$1ArrayDelegatingAdapterList.didAdd(int, Adapter) line: 503 MinimalEObjectImpl$1ArrayDelegatingAdapterList.didAdd(int, Object) line: 1 MinimalEObjectImpl$1ArrayDelegatingAdapterList(ArrayDelegatingEList<E>).addUnique(E) line: 395 MinimalEObjectImpl$1ArrayDelegatingAdapterList(AbstractEList<E>).add(E) line: 307 E4Workbench.<init>(MApplicationElement, IEclipseContext) line: 72
Null in the list (a multi-valued feature's value) is most likely caused by multi-theaded updates to the that list. You'll find it's not possible to add null into such a list so it should not be possible for such values to come out. The whole framework assumes such values can never be null, so patching one problem will just turn of the next, and the next and next, and in the end, a corrupted list is just not going to be fixed by such patching. Multi-threaded writes themselves need to be guarded by an appropriate threading policy. Even adding an adapter needs to be done in a thread safe way; thread safety is not provided by the underlying data structures.