Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 75835 - [EditorMgmt] [Contributions] Action Bars are not cleaned up after an Editor throws PartInitException
Summary: [EditorMgmt] [Contributions] Action Bars are not cleaned up after an Editor t...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 3.0.2   Edit
Assignee: Kim Horne CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 59301
Blocks:
  Show dependency tree
 
Reported: 2004-10-07 14:51 EDT by Dusko CLA
Modified: 2005-03-10 14:40 EST (History)
4 users (show)

See Also:


Attachments
Patch for org.eclipse.ui.workbench (1.69 KB, patch)
2004-10-26 14:52 EDT, Kim Horne CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dusko CLA 2004-10-07 14:51:55 EDT
If an Editor part throws a PartInitException during initialization (in the 
org.eclipse.ui.IEditorPart#init(IEditorSite, IEditorInput) method), the Action 
Bars are not cleaned up properly. This can cause problems. In my case I had 
following behavior:
1) An editor of type 1 would throw the PartInitException (and it has some 
toolbar actions defined)
2) Eclipse would deal with that and not display the editor (or the toolbar)
3) Another editor type (type 2) with a toolbar is invoked and everything opens 
properly
4) Close editor of type 2 - the toolbar of the editor type 1 is displayed and 
cannot be removed until the application is restarted.
I have tracked this down to the 
org.eclipse.ui.internal.EditorManager#createSite(...). Before calling part.init
(), it creates action bars but if init() throws an exception they are not 
disposed of. I checked the closeEditor method in the same class - it invokes 
the disposeEditorActionBars() method which is supposed to clean up the action 
bars. There are really no valid work-arounds (except not throwing the 
PartInititException which is part of the API) - all of these classes and 
methods are internal and even access private fields that are not exposed 
through getters. It seems that createSite() should catch the exception, call 
the disposeEditorActionBars() method and then re-throw.
Comment 1 Douglas Pollock CLA 2004-10-08 08:41:21 EDT
This only happens on an error condition, which shouldn't only happen during the 
development process. 
Comment 2 Douglas Pollock CLA 2004-10-08 10:31:05 EDT
From Dusko Misic: 
---------------- 
The reason why we marked the bug as 'Major' initially is that it is important 
for us that it gets fixed in 3.1. We are afraid that is not going to happen if 
its severity is 'Normal'. 
 
The fix seems very simple. On the other hand, to change our system not to throw 
the PartInitException (which is part of the public API anyway and is only way 
to indicate to Eclipse that the editor will not open) would be major 
undertaking. Basically, a lot of constructs assume that if that editor is open 
that it has right context and in this use case it wouldn't have. 
 
Could you let us know if the bug is going to be fixed for 3.1? 
Comment 3 Douglas Pollock CLA 2004-10-08 10:32:04 EDT
Okay, let me look a bit closer.  My initial reaction was to treat this as low 
priority, and to not go out of my way to fix it for 3.1. 
 
What is the behaviour in 3.0 (or 3.0.1)? 
Comment 4 Dusko CLA 2004-10-08 11:07:40 EDT
It is 3.0.1 but I believe that the behavior is the same in 3.0.
Basically, the editor part interface (org.eclipse.ui.IEditorPart) has method 
with following signature:

    public void init(IEditorSite site, IEditorInput input)
           throws PartInitException;

The PartInitException is thrown to indicate that the part (editor) cannot be 
initialized. Here is the quote from the javadoc:
‘Implementors of this method must examine the editor input object type to 
determine if it is understood.  If not, the implementor must throw a 
PartInitException.’

If that happens, Eclipse aborts creation of the editor and rolls back any 
contributions, objects, state changes, etc. done in order to create/open this 
editor. Of course, it is the editor’s responsibility to clean up things that 
it itself initialized before throwing the exception. The end result is that 
the Eclipse does not open the editor, displays the localized error msg (from 
the exception) and clean things up. The only exception to this rule is the bug 
in the org.eclipse.ui.internal.EditorManager#createSite(…) that does not 
perform the clean up.
In our case, that results in orphaned toolbars. Please note that there are 
very real use cases when the editor’s input type is not understood. Our use 
case was the user creating manually a dummy file with one of the extensions 
for which our editors are registered. The editor requires proper file 
structure so it cannot initialize correctly. A work around would be to still 
display the editor but with completely different content – basically a 
different implementation of the editor. That leads to another set of problems –
 all of those above mentioned things (like initialized toolbar) are not really 
valid anymore and can (and will) cause more problems.
It should be very easy to fix this problem. The EditorManager already has the 
method that performs the cleanup (disposeEditorActionBars). It just needs to 
be called in createSite(…) if the PartInitException happens and then re-throw 
the exception.
Comment 5 Douglas Pollock CLA 2004-10-08 11:20:08 EDT
Just to clarify, this problem exists in 3.0.1? 
Comment 6 Douglas Pollock CLA 2004-10-08 11:24:25 EDT
I believe this problem exists in 3.0 and 3.0.1, but does not exist in 2.1.3.  I 
believe this is a regression over 2.1.3 that must be fixed (violates API). 
 
I'm proposing this fix be considered for a 3.0.2 release. 
Comment 7 Stefan Xenos CLA 2004-10-08 20:29:38 EDT
Yeech. Even if we get the action bars cleaned up properly, I've got a number of
other PRs relating to bad things happening when an editor or view throws an
exception on initialization. We should really fix all of them, and that's a big
patch.

Because of all the formatting in 3.1, it's a real pain trying to get big patches
working in both streams. I'd suggest flagging this for 3.1 (and not 3.0.2).
Comment 8 Douglas Pollock CLA 2004-10-09 11:57:36 EDT
If you are having problems, then do the following: 
1.) Format all source code you want to change on the maintenance branch and 
commit. 
2.) If necessary, format all source code you want to change on the development 
branch and commit. 
3.) Make your patch. 
 
I still feel this particular problem is important for 3.0.2.  I don't know 
about any of the other problems.... 
 
Comment 9 Douglas Pollock CLA 2004-10-12 17:28:25 EDT
I believe this is the change introduced between revision 1.37 and 1.38 of 
EditorManager.  This is supposed to be the fix for Bug 59301. 
Comment 10 Kim Horne CLA 2004-10-26 14:51:01 EDT
Fixed in the maintenence stream.  Reviewed with DP.
Comment 11 Kim Horne CLA 2004-10-26 14:52:06 EDT
Created attachment 15402 [details]
Patch for org.eclipse.ui.workbench

The patch that was applied.   We wrapper the init method call and dispose the
action bars/site in the event that the init method failed for any reason.
Comment 12 Kim Horne CLA 2004-10-26 14:52:37 EDT
Marking as fixed.
Comment 13 Kim Horne CLA 2004-10-26 15:59:00 EDT
Also fixed in HEAD.  The fix in HEAD differs in that there is now a new message
in properties file to describe the error condition better.
Comment 14 Kim Horne CLA 2004-11-03 09:38:28 EST
Verified in 200411022000 for 3.1M3
Comment 15 Kim Horne CLA 2004-11-03 09:40:26 EST
Ooops, didnt mean to mark that as verified.  Leaving open for 3.0.2
Comment 16 Kim Horne CLA 2004-11-03 09:42:55 EST
Again marking as fixed.
Comment 17 Kim Horne CLA 2005-03-10 09:04:32 EST
Verified in 200502161722
Comment 18 Michael Van Meekeren CLA 2005-03-10 14:30:03 EST
Verified in 3.0.2 200502161722  (Linux/Motif)
Comment 19 Stefan Xenos CLA 2005-03-10 14:40:53 EST
This bug may need to be re-verified on the 3.1 stream, as the fix has changed
due to bug 87468