Bug 496668 - EditingSession.closeEditor() should work even when called from a non-UI thread
Summary: EditingSession.closeEditor() should work even when called from a non-UI thread
Status: NEW
Alias: None
Product: Sirius
Classification: Modeling
Component: Core (show other bugs)
Version: 4.0.0   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2016-06-23 12:02 EDT by Arthur Daussy CLA
Modified: 2016-07-06 00:00 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Arthur Daussy CLA 2016-06-23 12:02:40 EDT
In org.eclipse.sirius.ui.business.internal.session.EditingSession.closeEditor(DialectEditor, boolean) there is a fallback to close an editor that uses the code:

 PlatformUI.getWorkbench().getActiveWorkbenchWindow()

However the java doc of getActiveWorkbenchWindow state that it can return null if called from non UI Thread. In our case it leads to an NPE. Maybe this code should be guard against being called from a non UI thread.


!ENTRY org.eclipse.core.jobs 4 2 2016-06-23 17:54:34.690
!MESSAGE An internal error occurred during: "Chargement de la session de modélisation Equinoxe".
!STACK 0
java.lang.NullPointerException
	at org.eclipse.sirius.ui.business.internal.session.EditingSession.closeEditor(EditingSession.java:228)
	at org.eclipse.sirius.ui.business.internal.session.EditingSession.closeEditors(EditingSession.java:208)
	at org.eclipse.sirius.ui.business.internal.session.EditingSession.close(EditingSession.java:278)
	at org.eclipse.sirius.ui.business.internal.session.SessionUIManagerImpl.notify(SessionUIManagerImpl.java:139)
	at org.eclipse.sirius.business.internal.session.SessionManagerImpl.notifyUpdatedSession(SessionManagerImpl.java:142)
	at org.eclipse.sirius.business.internal.session.SessionManagerImpl.access$1(SessionManagerImpl.java:140)
	at org.eclipse.sirius.business.internal.session.SessionManagerImpl$1.notify(SessionManagerImpl.java:120)
	at org.eclipse.sirius.business.internal.session.danalysis.DAnalysisSessionImpl.notifyListeners(DAnalysisSessionImpl.java:1019)
	at org.eclipse.sirius.business.internal.session.danalysis.DAnalysisSessionImpl.close(DAnalysisSessionImpl.java:1201)
	at x.x.x.x.x.createHeaderAird(EqxSessionManager.java:147)
Comment 1 Laurent Fasani CLA 2016-06-27 08:20:06 EDT
I could effectively add a guard condition to avoid the NPE but it would be interesting to understand the what is done i the context of your scenario to check that everything is handled correctly.

It seems to be the a use case close to the one in Bug 496667 and here too I would be grateful if you could provide the elements (scenario or/and data) to reproduce this bug so that I can check the fix and create a junit test.
Comment 2 Pierre-Charles David CLA 2016-07-05 10:42:45 EDT
(In reply to Laurent Fasani from comment #1)
> I could effectively add a guard condition to avoid the NPE

We don't want as simple guard, at least not in the sense "if (inUIthread()) {...}". We would avoid the NPE, but if it means not doing what the method is expected to do and returning silently as if everything was fine, its worse than the NPE.

Depending on the calling context, either the client code should be in the UI thread or (more probably given the stack visible above), actually make sure what needs to be called in the UI thread is called in the UI thread.

In the standard (non-fallback) case, we do DialectUIManager.INSTANCE.closeEditor(editor, save), which ends up calling org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor.close(boolean), which ensures the final getSite().getPage().closeEditor() call is done in the UI thread. We should do something similar in our fallback case.
Comment 3 Pierre-Charles David CLA 2016-07-05 11:06:56 EDT
See https://git.eclipse.org/r/#/c/76617/ for a completly untested draft.
Comment 4 Eclipse Genie CLA 2016-07-06 00:00:31 EDT
New Gerrit change created: https://git.eclipse.org/r/76617