Community
Participate
Working Groups
Build Identifier: I20110613-1736 If a diff model contains an UpdateReference that has neither a left nor a right target, then the following NPE is thrown once its parent is expanded and the UpdateReferenceItemProvider is asked for an image for the UpdateReference instance. In addition, UpdateReferenceItemProvider.getText(...) also returns a wrong textual description ("Reference ... in ... changed from null to null" instead of "... changed from XYZ to null") here. java.lang.NullPointerException at org.eclipse.emf.edit.provider.ComposedAdapterFactory.adapt(ComposedAdapterFactory.java:340) at org.eclipse.emf.edit.provider.ComposedAdapterFactory.adapt(ComposedAdapterFactory.java:277) at org.eclipse.emf.compare.util.AdapterUtils.adapt(AdapterUtils.java:55) at org.eclipse.emf.compare.util.AdapterUtils.getItemProviderImage(AdapterUtils.java:79) at org.eclipse.emf.compare.diff.provider.UpdateReferenceItemProvider.getImage(UpdateReferenceItemProvider.java:58) at org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider.getImage(AdapterFactoryLabelProvider.java:336) at org.eclipse.emf.compare.ui.viewer.structure.ModelStructureMergeViewer$ModelStructureLabelProvider.getImage(ModelStructureMergeViewer.java:432) at org.eclipse.jface.viewers.WrappedViewerLabelProvider.getImage(WrappedViewerLabelProvider.java:117) at org.eclipse.jface.viewers.WrappedViewerLabelProvider.update(WrappedViewerLabelProvider.java:165) at org.eclipse.jface.viewers.ViewerColumn.refresh(ViewerColumn.java:152) at org.eclipse.jface.viewers.AbstractTreeViewer.doUpdateItem(AbstractTreeViewer.java:938) at org.eclipse.jface.viewers.AbstractTreeViewer$UpdateItemSafeRunnable.run(AbstractTreeViewer.java:106) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49) at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175) at org.eclipse.jface.viewers.AbstractTreeViewer.doUpdateItem(AbstractTreeViewer.java:1018) ... You will get a diff model with an UpdateReference where leftTarget = rightTarget = null by comparing two models, one of which sets a reference to an object that was newly added, for example: * Model 1 <?xml version="1.0" encoding="UTF-8"?> <ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="mypackage"> <eClassifiers xsi:type="ecore:EClass" name="A"> <eStructuralFeatures xsi:type="ecore:EReference" name="b" eType="#//B"/> </eClassifiers> <eClassifiers xsi:type="ecore:EClass" name="B"/> </ecore:EPackage> * Model 2 <?xml version="1.0" encoding="UTF-8"?> <ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="mypackage"> <eClassifiers xsi:type="ecore:EClass" name="A"> <eStructuralFeatures xsi:type="ecore:EReference" name="b"/> </eClassifiers> </ecore:EPackage> This is because ReferenceCheck.createUpdateReferenceOperation(...) uses EObject leftTarget = getMatchedEObject(addedValue); EObject rightTarget = getMatchedEObject(deletedValue); to compute the targets. In this case addedValue has no match and deletedValue is null (or vice versa) and so both targets are null. To fix this issue, UpdateReferenceItemProvider shouldn't use the UpdateReference's targets to compute the image and text. Instead it should use the reference value from leftElement and rightElement as already done in UpdateReferenceImpl.toString(). Reproducible: Always Steps to Reproduce: 1. Compare two models, one of which sets a reference to an object that was newly added (see examples above). 2. Expand the diff element that corresponds to the change of that reference. 3. An NPE is logged and the viewer shows a wrong textual description of the change.
Created attachment 202343 [details] Models to reproduce the issue
Created attachment 202396 [details] Patch for UpdateReferenceItemProvider r1.22 This patch changes UpdateReferenceItemProvider.getText(Object) and UpdateReferenceItemProvider.getImage(Object) to use the actual reference values of the left and right elements instead of the targets to compute the text or image, respectively. This fixes the issue described in the bug report and shouldn't change anything for all other cases. It may also be worth considering, to check the argument of AdapterUtils.adapt(EObject, Class) for null and return null in this case instead of letting ComposedAdapterFactory throw its NPE. Adding this check will make AdapterUtils.getItemProviderImage(Object) correctly return a null image for null.
Thanks Andreas. This patch has been commited on both master and the 1.2 maintenance branch. Changing AdapterUtils is something I am reluctant to do as we do not have tests for the UI itself.
batch-closing a bunch of "RESOLVED" bugs.