This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 434611 - modelService.cloneSnippet fails with NPE in a model processor
Summary: modelService.cloneSnippet fails with NPE in a model processor
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.4 RC1   Edit
Assignee: Lars Vogel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-12 02:37 EDT by Lars Vogel CLA
Modified: 2014-05-19 02:25 EDT (History)
4 users (show)

See Also:
pwebster: review+


Attachments
Stacktrace (2.68 KB, text/plain)
2014-05-12 02:37 EDT, Lars Vogel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Vogel CLA 2014-05-12 02:37:17 EDT
Created attachment 242952 [details]
Stacktrace

If I use the cloneSnippet method in a model processor I get a NPE because EPlaceholderResolver is null at this point in time.

Example:

    @Execute
    public void notWorkingexecute(EPartService partService, EModelService modelService, MApplication app) {

        // looking for the main window
        MWindow window = app.getChildren().get(0);

        // Cloning the snippet
        modelService.cloneSnippet(app, "test", window);

        // clonedPart.setParent((MElementContainer<MUIElement>) target);
    }

With I do the same with EMF functionality it works

     @Execute
        public
        void workingExecute(EPartService partService, EModelService modelService, MApplication app) {

        // cloning the snippet manualy using EMF
        MUIElement sourceSnippet = modelService.findSnippet(app, "com.intel.test.application.snippet.part.toput");
        MUIElement clonedPart = (MUIElement) EcoreUtil.copy((EObject) sourceSnippet);
        MUIElement target = modelService.find("test", app);

        clonedPart.setParent((MElementContainer<MUIElement>) target);
    }
Comment 1 Lars Vogel CLA 2014-05-12 02:56:17 EDT
EPlaceholderResolver is not null, it is the application.getContext() which is null.
Comment 2 Lars Vogel CLA 2014-05-12 02:58:09 EDT
(In reply to Lars Vogel from comment #1)
> EPlaceholderResolver is not null, it is the application.getContext() which
> is null.

((MApplication) appElement).getContext() returns null

EPlaceholderResolver resolver = ((MApplication) appElement).getContext().get(
					EPlaceholderResolver.class);
Comment 3 Lars Vogel CLA 2014-05-12 03:18:49 EDT
https://git.eclipse.org/r/26349
Comment 5 Lars Vogel CLA 2014-05-19 02:25:31 EDT
Verified in Build id: I20140515-1230