Bug 241827 [DataBinding] EMF + Databinding -> NullPointerException
The EMF model has 3 EClasseS: - Library; - Book(name:EString); - BookInfo(details:EString) The references are: Library -> (0..*, containment) Book; Book -> (0..1, containment) BookInfo; I want to display in a TableViewer (via EMF databinding) the following model information: - column 1: Book.name; - column 2: BookInfo:details; All is ok as long as every book has a not null BookInfo. As soon as a book has a null BookInfo the following exception occurs: java.lang.NullPointerException at org.eclipse.emf.databinding.EObjectObservableMap.hookListener(EObjectObservableMap.java:71) at org.eclipse.core.databinding.observable.map.ComputedObservableMap$1.handleSetChange(ComputedObservableMap.java:51) at org.eclipse.core.databinding.observable.set.SetChangeEvent.dispatch(SetChangeEvent.java:61) at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:129) at org.eclipse.core.databinding.observable.set.ObservableSet.fireSetChange(ObservableSet.java:67) at org.eclipse.core.databinding.observable.map.CompositeMap$WritableSetPlus.addAndRemove(CompositeMap.java:270) at org.eclipse.core.databinding.observable.map.CompositeMap$1.handleMapChange(CompositeMap.java:149) at org.eclipse.core.databinding.observable.map.MapChangeEvent.dispatch(MapChangeEvent.java:61) at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:129) at org.eclipse.core.databinding.observable.ChangeSupport.fireEvent(ChangeSupport.java:38) at org.eclipse.core.databinding.observable.map.AbstractObservableMap.fireMapChange(AbstractObservableMap.java:150) at org.eclipse.core.databinding.observable.map.ComputedObservableMap$1.handleSetChange(ComputedObservableMap.java:56) at org.eclipse.core.databinding.observable.set.SetChangeEvent.dispatch(SetChangeEvent.java:61) at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:129) at org.eclipse.core.databinding.observable.set.ObservableSet.fireSetChange(ObservableSet.java:67) at org.eclipse.core.internal.databinding.observable.UnmodifiableObservableSet.access$0(UnmodifiableObservableSet.java:1) at org.eclipse.core.internal.databinding.observable.UnmodifiableObservableSet$1.handleSetChange(UnmodifiableObservableSet.java:30) at org.eclipse.core.databinding.observable.set.SetChangeEvent.dispatch(SetChangeEvent.java:61) at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:129) at org.eclipse.core.databinding.observable.set.ObservableSet.fireSetChange(ObservableSet.java:67) at org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableSet.access$1(DetailObservableSet.java:1) at org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableSet$1.handleSetChange(DetailObservableSet.java:42) at org.eclipse.core.databinding.observable.set.SetChangeEvent.dispatch(SetChangeEvent.java:61) at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:129) at org.eclipse.core.databinding.observable.set.ObservableSet.fireSetChange(ObservableSet.java:67) at org.eclipse.core.databinding.observable.set.WritableSet.addAll(WritableSet.java:106) at org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableSet.addAll(DetailObservableSet.java:116) at org.eclipse.jface.internal.databinding.viewers.ObservableCollectionContentProvider.setInput(ObservableCollectionContentProvider.java:151) at org.eclipse.jface.internal.databinding.viewers.ObservableCollectionContentProvider.inputChanged(ObservableCollectionContentProvider.java:115) at org.eclipse.jface.databinding.viewers.ObservableListContentProvider.inputChanged(ObservableListContentProvider.java:110) at org.eclipse.jface.viewers.ContentViewer.setInput(ContentViewer.java:247) at org.eclipse.jface.viewers.StructuredViewer.setInput(StructuredViewer.java:1603) at ro.jtonic.tests.test1.Test2.initializeBindings(Test2.java:87) at ro.jtonic.tests.test1.Test2.createPartControl(Test2.java:57) at org.eclipse.ui.internal.ViewReference.createPartHelper(ViewReference.java:371) at org.eclipse.ui.internal.ViewReference.createPart(ViewReference.java:230) at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:594) at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:306) at org.eclipse.ui.internal.ViewPane.setVisible(ViewPane.java:531) at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:180) at org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:270) at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65) at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:473) at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1256) at org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:1209) at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:1608) at org.eclipse.ui.internal.PartStack.createControl(PartStack.java:649) at org.eclipse.ui.internal.PartStack.createControl(PartStack.java:576) at org.eclipse.ui.internal.PartSashContainer.createControl(PartSashContainer.java:568) at org.eclipse.ui.internal.PerspectiveHelper.activate(PerspectiveHelper.java:271) at org.eclipse.ui.internal.Perspective.onActivate(Perspective.java:964) at org.eclipse.ui.internal.WorkbenchPage.onActivate(WorkbenchPage.java:2593) at org.eclipse.ui.internal.WorkbenchWindow$25.run(WorkbenchWindow.java:2869) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70) at org.eclipse.ui.internal.WorkbenchWindow.setActivePage(WorkbenchWindow.java:2850) at org.eclipse.ui.internal.WorkbenchWindow.busyOpenPage(WorkbenchWindow.java:759) at org.eclipse.ui.internal.Workbench$21.runWithException(Workbench.java:1027) at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31) at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:133) at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3800) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3425) at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:803) at org.eclipse.ui.internal.Workbench$27.runWithException(Workbench.java:1361) at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31) at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:178) at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150) at org.eclipse.swt.widgets.Display.syncExec(Display.java:4251) at org.eclipse.ui.internal.StartupThreading.runWithoutExceptions(StartupThreading.java:94) at org.eclipse.ui.internal.Workbench.init(Workbench.java:1356) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2312) at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198) at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:488) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at ro.jtonic.tests.test1.Application.start(Application.java:20) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:382) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504) at org.eclipse.equinox.launcher.Main.run(Main.java:1236) at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/ComputedObservableMap.java
import org.eclipse.core.databinding.observable.set.SetChangeEvent;
/**
 * Maps objects to one of their attributes. Tracks changes to the underlying
 * observable set of objects (keys), as well as changes to attribute values.
 */
public abstract class ComputedObservableMap extends AbstractObservableMap {
	private IObservableSet keySet;
	
	private Object valueType;
	private ISetChangeListener setChangeListener = new ISetChangeListener() {
		public void handleSetChange(SetChangeEvent event) {
			Set addedKeys = new HashSet(event.diff.getAdditions());
			Set removedKeys = new HashSet(event.diff.getRemovals());
			Map oldValues = new HashMap();
			Map newValues = new HashMap();
			for (Iterator it = removedKeys.iterator(); it.hasNext();) {
				Object removedKey = it.next();
				Object oldValue = doGet(removedKey);
				unhookListener(removedKey);
				if (oldValue != null) {
					oldValues.put(removedKey, oldValue);
				}
			}
			for (Iterator it = addedKeys.iterator(); it.hasNext();) {
				Object addedKey = it.next();
				hookListener(addedKey);
				Object newValue = doGet(addedKey);
				newValues.put(addedKey, newValue);
			}
			fireMapChange(Diffs.createMapDiff(addedKeys, removedKeys,