Bug 270571 - [MPE] Race condition when starting Eclipse with multipl editors opened
Summary: [MPE] Race condition when starting Eclipse with multipl editors opened
Status: RESOLVED DUPLICATE of bug 151488
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact: Paul Webster CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-31 05:27 EDT by Dennis Nguyen CLA
Modified: 2009-04-08 19:19 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dennis Nguyen CLA 2009-03-31 05:27:25 EDT
Build ID: M20080221-1800

Steps To Reproduce:
This happen when we try to subclasses MultiPageEditorActionBarContributor, then extends
MultiPageEditorActionBarContributor#setActiveEditor to hook actions in toolbar with our active editor

1. Open multiple editors (let say 4), each associated with a different files
2. Focus on one editor in the middle (let say editor 2)
3. Close eclipse, then re-opened it

Result: race condition within setActiveEditor(). By printing the activeEditor title, I've got something like this:

editor 2
editor 2
editor 1
editor 3
editor 4

As such, we incorrectly associated our action with editor 4, even though the focused and active editor is number 2. So when user invokes one of the actions, its effect is on editor 4 !!!

More information:
This probably happens because our setActive() runs quite long. But I tried to synchronized this method and it doesn't work. Our work around at the moment is to re-target the active editor to 

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()

when the above is not null and doesn't cause NPE.
Comment 1 Paul Webster CLA 2009-03-31 14:32:25 EDT
Can you include a small MPEP sample plugin with an example that shows the failure?  Is it that you are opening 4 MPEPs or you are opening one MPEP with 4 internal editors?

PW
Comment 2 Dennis Nguyen CLA 2009-04-08 04:05:48 EDT
Sorry for the long delay.

@Paul: I am not sure how to answer your question, so please let me know if I misunderstand your question.

I start up 1 eclipse, then open 4 files in our editor (an extension of WST XML editor). 

Today, I use the wizard to create a simple text editor, then open 4 text files. Close eclipse, reopen it again, but the active editor is only invoke 1.

Again, use wizard to create a simple XML editor, but I still can't reproduce the error.

I am starting to think that this is either our plugin specific problem, or WST UI problem. I tested again with our editor and the problem is still there. I obtained the stack trace where setActiveEditor() is call, and will get back to you if anything interesting is in there.
Comment 3 Paul Webster CLA 2009-04-08 08:35:42 EDT
(In reply to comment #2)
> I start up 1 eclipse, then open 4 files in our editor (an extension of WST XML
> editor). 

OK, I think I was just asking if it was 4 editors open or one MPEP open with 4 "inner" editors.  It sounds like the 4 separate MPEP editors.

If you get a stack trace from startup (and annotate it somehow) and attach it as a text file I can have a look at it as well.

PW
 
Comment 4 Dennis Nguyen CLA 2009-04-08 19:19:19 EDT
ok, find the culprit in org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart.createPages(), which our editor subclasses.

// set the active editor in the action bar contributor first
// before setactivepage calls action bar contributor's
// setactivepage (bug141013 - remove when bug151488 is fixed)
IEditorActionBarContributor contributor = getEditorSite().getActionBarContributor();
if (contributor instanceof MultiPageEditorActionBarContributor) {
    ((MultiPageEditorActionBarContributor) contributor).setActiveEditor(this);
}


Even though my code is using R2_0 maintenance release, this issue still persist with the latest code.

I guess I'll make this a duplication of 151488 and closed

*** This bug has been marked as a duplicate of bug 151488 ***