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

Bug 163325

Summary: DeferredUpdateManager should not use Display.getCurrent()
Product: [Tools] GEF Reporter: Hannes Niederhausen <hniederhausen>
Component: GEF-Legacy Draw2dAssignee: gef-inbox <gef-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: enhancement    
Priority: P3    
Version: 3.2.1   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Hannes Niederhausen CLA 2006-11-03 08:01:33 EST
In the method sendUpdateRequest a new thread is created using the asyncExec method of the Display class. The problem is, that the Display instance is fetched by the static getCurrent() method which only returns a display if the current thread is a graphical thread.

I currently have the problem, that I call per listeners the refresh method of my EditParts in a non graphical thread and therfore I get an exception instead of a refreshed editor.

A better solution would be to fetch the Display instance from the workbench e.g. InternalGEFPlugin.getDefault().getWorkbench().getDisplay();
Comment 1 Randy Hudson CLA 2006-11-03 09:42:46 EST
GEF and draw2d are not thread safe. Therefore, you can not access your editparts or figures from multiple threads. If you could do this, you will end up with ArrayIndexOutOfBounds and other exceptions. You must use syncExec or asyncExec to access your editparts from the appropriate thread.
Comment 2 Anthony Hunter CLA 2006-11-03 10:09:33 EST
Is this the only issue you are having with this use case? Display.getCurrent() is null?
Comment 3 Hannes Niederhausen CLA 2006-11-03 10:23:24 EST
The use case is: I started programming a kind of UML Editor and wanted to syncronize with the jdt. The reconciler, which fires the code change events works in a different thread and so my listener refreshs the editparts in the same thread.

After using Display.syncExec I had no other problems.

I just wondered why I have to start a new thread only to allow draw2d to start another thread. 
Comment 4 Randy Hudson CLA 2006-11-03 13:31:05 EST
If you refresh your editparts in one thread, and the Main thread is in the middle of editing the model, painting, laying out, performing hit-testing for the mouse, or many other things which involve reading or writing the figures, you will have subtle threading issues. Debugging the NPE you saw is much easier than tracking down thread-related bugs.

JDT has to do the same thing when they respond to these notifications. If they are updating an SWT tree, they use (a)syncExec.