Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 325648 - Template used by GMF that generates ???DiagramEditor.java should check for null diagram or resource in the getNavigatorSelection method
Summary: Template used by GMF that generates ???DiagramEditor.java should check for nu...
Status: RESOLVED FIXED
Alias: None
Product: GMF-Tooling
Classification: Modeling
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 2.4   Edit
Assignee: Artem Tikhomirov CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-17 15:57 EDT by Luis Rocha CLA
Modified: 2011-07-14 07:51 EDT (History)
2 users (show)

See Also:


Attachments
Proposed patch (1.01 KB, patch)
2010-11-12 11:03 EST, Mickael Istria CLA
tikhomirov.artem: iplog+
tikhomirov.artem: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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