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

Bug 345745

Summary: [Compatibility] Editors occasionally fail to persist state (org.eclipse.ui.internal.emptyEditorTab)
Product: [Eclipse Project] e4 Reporter: Brian de Alwis <bsd>
Component: UIAssignee: Remy Suen <remy.suen>
Status: RESOLVED FIXED QA Contact: Remy Suen <remy.suen>
Severity: normal    
Priority: P3 CC: daniel_megert, emoffatt, Mike_Wilson, pwebster, remy.suen
Version: unspecifiedFlags: Mike_Wilson: pmc_approved+
pwebster: review+
Target Milestone: 4.1 RC4   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Restart patch v1 none

Description Brian de Alwis CLA 2011-05-13 11:09:36 EDT
I've noticed on occasion when restarting that all of the editors in one perspective are not recovered and instead show an "org.eclipse.ui.internal.emptyEditorTab" editor.

I usually have each perspective configured to open in a separate window, and usually develop with two perspectives open, a Java Browsing perspective and a Debug perspective.  To my recollection, when this problem has occurred, it has occurred in the Java Browsing perspective.

The problem is unfortunately sporadic: it works sometimes, and doesn't others.

The problem occurs during the persisting as the editor references in the deltas.xml are missing their persistedState map.  There is nothing in the log indicating an error other than a stack trace due to bug 338221 — perhaps the model is being persisted twice but the state is different on the second time?
Comment 1 Brian de Alwis CLA 2011-05-18 12:47:05 EDT
I had wondered if this bug might be related to the exit-not-prompting bug (bug 338221 which caused a the shutdown procedure to execute twice) but this bug just happened to me when switching between workspaces.
Comment 2 Remy Suen CLA 2011-06-06 10:19:12 EDT
I got this just now with I20110604-2201 on Windows XP.

I had three workbench windows and initated a restart via 'File > Restart'.
Comment 3 Remy Suen CLA 2011-06-06 10:46:25 EDT
I20110604-2201

1. Wipe your deltas.
2. Start Eclipse.
3. Open a local file in your workspace.
4. Window > New Window
5. File > Restart
6. Eclipse will return but the editor will not have been restored.
Comment 4 Remy Suen CLA 2011-06-06 13:47:13 EDT
1. Open a file.
2. Make the editor dirty.
3. Window > New Window
4. File > Restart
5. When prompted to save, click 'Cancel'.
6. The second workbench window is closed.

All these problems are a generic issue with the implementation and use of the IPresentationEngine's stop() method. Shells are just closed "randomly" with no regard of what happened in the other windows so step 6 happens. Editors do not get persisted properly because the controls simply get disposed so the workbench's internal shutdown code never happens.
Comment 5 Remy Suen CLA 2011-06-06 14:59:00 EDT
This bug also means that a view's saveState(IMemento) method will not be called on restart.
Comment 6 Remy Suen CLA 2011-06-07 10:06:20 EDT
This also means that editor implementations that implement the IPersistableEditor interface won't be able to save information in a memento.
Comment 7 Remy Suen CLA 2011-06-09 12:19:26 EDT
Created attachment 197703 [details]
Restart patch v1

I am suggesting we fix this bug for 4.1 GA.

IMPACTED USERS:
Anybody that uses two or more workbench windows. This problem is not noticeable to anyone with only one workbench window because we detect the single window case and will initiate the regular shutdown sequence.

BACKGROUND:
The current restart request only goes through the rendering engine's stop() method. The current implementation closes every single shell indiscriminately. This is wrong in many ways.

The most obvious problem in question is that the cancellation of this operation does not prevent the other shells from being closed (see comment 4). Arbitrarily closing workbench windows even when the user has chosen to cancel something leads to frustrated users as the layout of their views and editors have now been lost in those other workbench windows.

By simply closing the shells without going through our specialized shutdown cycle, editors and views also do not get a chance to clean themselves up so any state that is usually saved in a memento does not get stored on a restart (see comment 5 and comment 6). This also means that the editor inputs do not get persisted so all opened editors on the eagerly closed shells will not get restored on the next startup. This implies that the user has to reopen all of those editors by hand. Not necessarily a direct data loss but an annoyance nonetheless.

Please note that dirty parts do get prompted as needing to be saved even in the currently bad code. This behaviour is of course unchanged and will continue to function with the patch.

GOALS/BENEFITS:
Restart is a common scenario after having installed some plug-ins (which we want consumers to do with 4.1) and making the restart cycle correctly persist their data will ensure that they do not have a sour taste in their mouths when Eclipse comes back up. Having their editors return not persisted properly may give them the impression that their plug-ins were the problem and may send them the message that our compatibility layer implementation is not ready.

RELATED BUGS:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=312821

RISKS:
Minimal. By calling the same close(int, boolean) method that our regular shutdown calls, we can ensure that anyone that uses IWorkbench's API restart() method will have the application shutdown and restart in a way that they expect it to work in 3.x.

I was initially hesitant about removing the changes for bug 312821 but to ensure that the shutdown sequence is identical to what happens with a 'File > Exit', I decided that we should remove those extra checks which would guarantee that both shutdown and restart would go through the _exact_ code path.

PERFORMANCE IMPACT:
Negligible. Restart will be slower (but correct). The speed will be identical to a regular 'File > Exit' shutdown case.
Comment 8 Remy Suen CLA 2011-06-09 12:19:59 EDT
(In reply to comment #7)
> Created attachment 197703 [details]
> Restart patch v1

Paul, please take a look.
Comment 9 Paul Webster CLA 2011-06-09 16:08:19 EDT
Makes sense, and makes the code simpler.

PW
Comment 10 Remy Suen CLA 2011-06-09 16:52:34 EDT
(In reply to comment #7)
> Created attachment 197703 [details]
> Restart patch v1

Patch released to CVS HEAD. Thanks for reporting the bug, Brian!