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

Bug 325648

Summary: Template used by GMF that generates ???DiagramEditor.java should check for null diagram or resource in the getNavigatorSelection method
Product: [Modeling] GMF-Tooling Reporter: Luis Rocha <lerocha>
Component: CoreAssignee: Artem Tikhomirov <tikhomirov.artem>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: mariot.chauvin, mistria
Version: unspecified   
Target Milestone: 2.4   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Proposed patch tikhomirov.artem: iplog+, tikhomirov.artem: review+

Description Luis Rocha CLA 2010-09-17 15:57:56 EDT
Build Identifier: 20100218-1602

The generated getNavigatorSelection method in ???DiagramEditor.java does not check for null diagram or resource. This can be a problem when we are implementing diagram partitioning with shared editing domain as described in   http://wiki.eclipse.org/GMF_Tips#Sharing_single_EditingDomai n_instance_across_several_diagrams. 

In this case we can have a null resource and then a java.lang.NullPointerException will occur when getNavigatorSelection calls WorkspaceSynchronizer.getFile passing null.

In order to fix this, we could manually change the generated code as shown below, but it is better to fix the original template used to generated it.

    private ISelection getNavigatorSelection() {
        ...
        Diagram diagram = document.getDiagram();

        // Modification started. 
        if (diagram == null || diagram.eResource() == null) {
            return StructuredSelection.EMPTY;
        }
        // Modification ended.
        
        IFile file = WorkspaceSynchronizer.getFile(diagram.eResource());
        ...
    }

This has been discussed in the following forum message:
http://www.eclipse.org/forums/index.php?t=rview&goto=559558&th=175421#msg_559558

Reproducible: Always

Steps to Reproduce:
1. Generate the diagram code from a gmfgen file.
2. Open the generated ???DiagramEditor.java file.
3. Look for the getNavigatorSelection method.
Comment 1 Mickael Istria CLA 2010-11-12 11:03:03 EST
Created attachment 183007 [details]
Proposed patch

This patch should add the necessary check and avoid the NPE.
Comment 2 Artem Tikhomirov CLA 2010-12-09 23:08:34 EST
Comment on attachment 183007 [details]
Proposed patch

Although it's not apparent how come shared editing domain leads to null resource for a diagram, the null check seems to be appropriate there.
Comment 3 Artem Tikhomirov CLA 2010-12-09 23:09:33 EST
committed.
Comment 4 Michael Golubev CLA 2011-07-13 19:45:49 EDT
version -> 2.4
Comment 5 Michael Golubev CLA 2011-07-14 07:51:37 EDT
Rollback, Set target to 2.4 instead of accidenatlly set Version