Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 340403 - Calling addGraphicalRepresentation from a Custom Feature results in NullPointerException
Summary: Calling addGraphicalRepresentation from a Custom Feature results in NullPoint...
Status: CLOSED FIXED
Alias: None
Product: Graphiti
Classification: Modeling
Component: Core (show other bugs)
Version: 0.7.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 0.8.0   Edit
Assignee: Michael Wenz CLA
QA Contact:
URL:
Whiteboard: Indigo M7 theme_bugs
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-18 04:45 EDT by Jan Schoubo CLA
Modified: 2011-06-24 09:13 EDT (History)
3 users (show)

See Also:
michael.wenz: indigo+


Attachments
full stacktrace (2.08 KB, text/plain)
2011-03-18 04:46 EDT, Jan Schoubo CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Schoubo CLA 2011-03-18 04:45:52 EDT
Build Identifier: 20110218-0911

I am trying to create an import function as a Custom Feature (more details in Forum message #659779 and followup). The straightforward code works when placed directly in the Custom Feature's execute(), but shows no feedback during the lengthy operation.

When I add a Progress Monitor and move the logic into a org.eclipse.ui.progress.Job, each call to addGraphicalRepresentation now results in a Null Pointer Exception in org.eclipse.graphiti.ui.internal.editor.DomainModelChangeListener.resourceSetChanged(DomainModelChangeListener.java:109) - it seems SWT has no Display.getCurrent() value available, when executing in a separate thread.

However, the progress monitor works, the elements show up along the way, and the end result - apart from tons of stacktraces and a popup warning - seems correct.

I also tried changing the Job to a UIJob, that made the stacktraces and popup go away, but also the progress monitor, and after 30 seconds of nothing, the display started to chase around like mad, to catch up on all the UI updates that had build up. Very entertaining, but not what I had hoped for :-)



[Forum comment (#660282) from Michael Wenz]
Short answer to this: this appears to be a bug. Display.getCurrent() returns
null when called from the non-UI thread. We should instead use
Display.getDefault(). 


Small related problem: addGraphicalRepresentation is declared protected in AbstractFeature, so I have to create a callback method in my Custom Feature?
Any particular reason why this cannot be public?



Reproducible: Always

Steps to Reproduce:
1. Create Custom Feature and tie to a Context Menu as in the tutorial
2. Do this a lot of times in a loop:
3.   Create a business object
3.   Create an AddContext
4.   Call addGraphicalRepresentation on those
Comment 1 Jan Schoubo CLA 2011-03-18 04:46:46 EDT
Created attachment 191488 [details]
full stacktrace
Comment 2 Michael Wenz CLA 2011-03-18 10:12:54 EDT
I have changed the async exec call to use Display.getDefault() instead of Display.getCurrent; now this should work in all threads.

To the related problem: instead of calling addGraphicalRepresentation from AbstractFeature, you should call addIfPossible in your feature provider; this method is public and addGraphicalRepresentation simply delegates to it.

Michael
Comment 3 Michael Wenz CLA 2011-06-24 09:13:36 EDT
Part of Graphiti Indigo 0.8.0