Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 508036

Summary: NPE when pasting format on diagram with hidden element
Product: [Modeling] Sirius Reporter: Pierre Guilet <pierre.guilet>
Component: DiagramAssignee: Project Inbox <sirius.diagram-inbox>
Status: CLOSED FIXED QA Contact: Florian Barbin <florian.barbin>
Severity: normal    
Priority: P3 CC: florian.barbin, julien.dupont, pierre-charles.david
Version: 4.1.0Keywords: triaged
Target Milestone: 4.1.2   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/85594
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=cb11744b51780fa8ae0b06a76b56a6afe5792d51
Whiteboard:
Attachments:
Description Flags
project to reproduce none

Description Pierre Guilet CLA 2016-11-23 05:25:11 EST
Created attachment 265537 [details]
project to reproduce

When pasting format on the root element of a diagram, we don't take in consideration the possibility that sub element of root element does not have an edit part because it is hidden whereas it was not in copied diagram leading to the following NPE :

Caused by: java.lang.NullPointerException
	at org.eclipse.sirius.diagram.ui.tools.internal.format.FormatDataHelperImpl.getRelativeLocation(FormatDataHelperImpl.java:250)
	at org.eclipse.sirius.diagram.ui.tools.api.format.AbstractSiriusFormatDataManager.applyFormat(AbstractSiriusFormatDataManager.java:425)
	at org.eclipse.sirius.diagram.ui.tools.api.format.AbstractSiriusFormatDataManager.applyFormat(AbstractSiriusFormatDataManager.java:217)
	at org.eclipse.sirius.diagram.ui.tools.api.format.AbstractSiriusFormatDataManager.applyFormat(AbstractSiriusFormatDataManager.java:180)
	at org.eclipse.sirius.diagram.ui.tools.api.format.AbstractSiriusFormatDataManager.applyFormat(AbstractSiriusFormatDataManager.java:138)
	at org.eclipse.sirius.diagram.ui.tools.internal.actions.layout.PasteFormatAction$PasteFormatDataCommand.doExecuteWithResult(PasteFormatAction.java:185)
	at org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand.doExecute(AbstractTransactionalCommand.java:247)
	at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:150)
	at org.eclipse.sirius.diagram.ui.tools.internal.commands.WrappingCommandIgnoringAffectedFiles.execute(WrappingCommandIgnoringAffectedFiles.java:124)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:516)
	... 46 more


In org.eclipse.sirius.diagram.ui.tools.api.format.AbstractSiriusFormatDataManager.applyFormat(DDiagram, Diagram, EditPartViewer, boolean, boolean)
we iterate over all sub node by the ownedDiagramElement reference :

 for (final AbstractDNode node : Iterables.filter(diagram.getOwnedDiagramElements(), AbstractDNode.class)) {
            final Node gmfNode = SiriusGMFHelper.getGmfNode(node);
            if (gmfNode != null) {
                applyFormat(node, gmfNode, editPartViewer, null, applyFormat, applyStyle);
            }
        }

and applyFormat on each item.

In the applyFormat call we do the following :
 if (formatData != null && applyFormat) {

            final Bounds bounds = NotationFactory.eINSTANCE.createBounds();
            final IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) editPartViewer.getEditPartRegistry().get(toRestoreView);

But at this point, we get a null as corresponding edit part because it is hidden. 
We should have a null check here. 
 

Steps to reproduce :
1-Import attached project
2-Open diagram "DiagType2 of MyPackage"
3-Right click on diagram root element>Edit>Copy format
4-Open diagram "Type10 Raw Diagram"
5-Right click on diagram root element>Edit>Paste format
6-You have the NPE in error log
Comment 1 Eclipse Genie CLA 2016-11-23 10:10:22 EST
New Gerrit change created: https://git.eclipse.org/r/85594
Comment 3 Pierre Guilet CLA 2016-11-28 04:51:51 EST
Associated test : 

Gerrit change https://git.eclipse.org/r/85598 was merged to [master].
Commit: http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=8dadc572a41ead59b252e84e97704a285170306f
Comment 4 Florian Barbin CLA 2016-12-01 09:13:03 EST
Verified on Sirius 4.1.2.201612011000.
Comment 5 Pierre-Charles David CLA 2016-12-08 11:12:58 EST
Available in Sirius 4.1.2 (see https://wiki.eclipse.org/Sirius/4.1.2 for details).