Bug 457939 - MUIElement#setCurSharedRef is never cleared when hiding recursively
Summary: MUIElement#setCurSharedRef is never cleared when hiding recursively
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.5   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.5 M7   Edit
Assignee: Dirk Fauth CLA
QA Contact:
URL:
Whiteboard:
Keywords: greatfix
Depends on:
Blocks:
 
Reported: 2015-01-20 09:27 EST by Jacek Bukowski CLA
Modified: 2015-04-28 16:09 EDT (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jacek Bukowski CLA 2015-01-20 09:27:27 EST
I have an application in which I build dynamically the user interface based on some recipe. It is done by having perspectives defined as snippets and all parts in window's shared elements. The perspectives then are cloned from snippets and filled with placeholders dynamically. The placeholders reference to the parts in shared elements.
One of the part needs to display all available parts, so basically it retrieves all MParts from shared elements and display them using MPart.getLocalizedLabel(). It all works fine if the parts haven't been attached to any placeholder yet or they are assigned by they are visible in the same perspective. If I try to get localized label of the part which previously was referenced by the placeholder, I get just key (so exactly the same as MPart.getLabel()).

After debugging it seems that the problem is that 'Cur Shared Ref' of the part is never cleared even if corresponding placeholder is removed from the model (e.g. by EModelService.removePerspectiveModel()). LocalizationHelper.getLocalized() uses ModelUtils.getContainingContext(). That has a special if-case for parts attached to placeholders, but the context of the placeholder is null in my case. I have checked with both SWT renderers and JavaFX renderers.

If I just manually set null to 'Cur Shared Ref', then retrieving localized label works fine.

I tried on Juno SR1 release.

Please also see discussion with Tom Schindl: https://www.eclipse.org/forums/index.php/t/953042/
Comment 1 Thomas Schindl CLA 2015-01-20 10:02:36 EST
For reference - i fixed this bug in the fx-renderers in the perspective code when a perspective selection is changed.

The logic (and I think it is the same in the SWT renderer is):
* detect the selection change
* recursively walk the widget tree of the old selection hiding stuff
* recursively walk the widget tree of the new selection makeing stuff visible

The fix in the fx-renders is simply that when doing the recurive hideing i set the curRef to null and which in turn gets reset on the recursive makeing visible call afterwards
Comment 2 Eclipse Genie CLA 2015-02-06 16:52:32 EST
New Gerrit change created: https://git.eclipse.org/r/41337
Comment 3 Dirk Fauth CLA 2015-02-06 16:56:41 EST
I think I've found the solution for this issue.

@Tom
It would be great if you could review the change. I had a hard time finding the right position, since there is no SWT placeholder renderer.
Comment 4 Dirk Fauth CLA 2015-02-25 06:46:46 EST
To evaluate my patch, have a look at my translation example on GitHub

https://github.com/fipro78/e4translationexample

If you start the application there is a subwindow that shows a "Kill perspective" button. On click a perspective is killed and the also killed shared part shows the key instead of the translation in the part.

My patch should solve this according to the discussion in the forum and the solution Tom found for JavaFX.
Comment 5 Dirk Fauth CLA 2015-03-25 04:02:49 EDT
The patch seems to raise another issue with missing checks for curSharedRef == null in intro code.

see Bug 463043 for further information
Comment 7 Brian de Alwis CLA 2015-04-02 11:23:42 EDT
Thanks Dirk.  Fixed for M7.
Comment 8 Andrey Loskutov CLA 2015-04-06 03:33:04 EDT
Probably this fix caused regression, see bug 463957.
Comment 9 Eclipse Genie CLA 2015-04-06 05:29:01 EDT
New Gerrit change created: https://git.eclipse.org/r/45314
Comment 10 Andrey Loskutov CLA 2015-04-06 05:30:14 EDT
(In reply to Eclipse Genie from comment #9)
> New Gerrit change created: https://git.eclipse.org/r/45314

Patch https://git.eclipse.org/r/41337/ introduced serious regression in IDE (bug 463962).

Reverting commit 21a06ea739e3c429b7ba3a60d0254673d0cd0b5e (patch https://git.eclipse.org/r/45314) fixes bug 463962.
Comment 11 Dirk Fauth CLA 2015-04-06 05:56:13 EDT
(In reply to Andrey Loskutov from comment #10)
> (In reply to Eclipse Genie from comment #9)
> > New Gerrit change created: https://git.eclipse.org/r/45314
> 
> Patch https://git.eclipse.org/r/41337/ introduced serious regression in IDE
> (bug 463962).
> 
> Reverting commit 21a06ea739e3c429b7ba3a60d0254673d0cd0b5e (patch
> https://git.eclipse.org/r/45314) fixes bug 463962.

So you simply remove my contribution?

Why not checking the cause for the NPE?

Looking into the code this line is responsible for the NPE

if (selectedPart.getParent().getRenderer() != null) {

So selectedPart.getParent() is null. Shouldn't that be checked before going further?
Comment 12 Andrey Loskutov CLA 2015-04-06 06:11:00 EDT
(In reply to Dirk Fauth from comment #11)
> (In reply to Andrey Loskutov from comment #10)
> > (In reply to Eclipse Genie from comment #9)
> > > New Gerrit change created: https://git.eclipse.org/r/45314
> > 
> > Patch https://git.eclipse.org/r/41337/ introduced serious regression in IDE
> > (bug 463962).
> > 
> > Reverting commit 21a06ea739e3c429b7ba3a60d0254673d0cd0b5e (patch
> > https://git.eclipse.org/r/45314) fixes bug 463962.
> 
> So you simply remove my contribution?

Not yet, but I tend to do it.

If you have a fix for bug 463962 I will be glad *not* to do it, but bug 463962 is a showstopper IMHO.
 
> Why not checking the cause for the NPE?

The problem is that the NPE seems to be NOT the root cause, it is another manifestation of the same problem.

I'm still trying to figure out how to stable reproduce the issue. Sometimes steps described in bug 463962 are not enough, but it looks like reverting your change fixes the issue.
Comment 13 Dirk Fauth CLA 2015-04-06 06:19:58 EDT
No the problem is that we already know that we are a MPlaceholder, but checking this information again by looking into the curSharedRef.

I'll work on a solution, give me some time.
Comment 14 Andrey Loskutov CLA 2015-04-06 07:45:42 EDT
(In reply to Dirk Fauth from comment #13)
> No the problem is that we already know that we are a MPlaceholder, but
> checking this information again by looking into the curSharedRef.
> 
> I'll work on a solution, give me some time.

Dirk, thanks for quick response. Is this https://git.eclipse.org/r/45317/ the *final* fix, or are you still debugging? The fix seems to work for me.
Comment 15 Dirk Fauth CLA 2015-04-06 07:47:39 EDT
(In reply to Andrey Loskutov from comment #14)
> (In reply to Dirk Fauth from comment #13)
> > No the problem is that we already know that we are a MPlaceholder, but
> > checking this information again by looking into the curSharedRef.
> > 
> > I'll work on a solution, give me some time.
> 
> Dirk, thanks for quick response. Is this https://git.eclipse.org/r/45317/
> the *final* fix, or are you still debugging? The fix seems to work for me.

From my point of view it should be the *final* fix, at least if it works for you. :-)
Comment 16 Eclipse Genie CLA 2015-04-06 14:50:22 EDT
New Gerrit change created: https://git.eclipse.org/r/45333
Comment 17 Brian de Alwis CLA 2015-04-06 15:05:21 EDT
Here are the problematic locations I've found:

StackRenderer#createTab assumed the placeholder has a ref; I hit this problem while tracking down a different problem and can't remember how I created it :-(


WorkbenchPage#showView(VIEW_VISIBLE) assumes parts shown EPartService#showPart() will have a curSharedRef, though the PartServiceImpl#bringToTop has checks in case the curSharedRef is null.  I haven't been able to trigger this code path ever occurs in practice, so it's a defensive measure.


MinMaxAddon: several places uses the curSharedRef without checking for null.  But in my testing, this code assumes minimization and maximization only happens in the active perspective (i.e., setting 'Maximized' on part stacks in other perspectives fails in a spectacular manner).  This is a bigger problem, so I've submitted this as bug 463985.
Comment 18 Andrey Loskutov CLA 2015-04-10 18:05:28 EDT
Follow up on https://dev.eclipse.org/mhonarc/lists/platform-ui-dev/msg06164.html

The failures below appeared after integration of https://git.eclipse.org/r/41337/ (commit 21a06ea739e3c429b7ba3a60d0254673d0cd0b5e, bug 457939).

Hope this helps. 

testBug334580_01(org.eclipse.e4.ui.tests.workbench.PartRenderingEngineTests)
junit.framework.AssertionFailedError
    at junit.framework.Assert.fail(Assert.java:55)
    at junit.framework.Assert.assertTrue(Assert.java:22)
    at junit.framework.Assert.assertTrue(Assert.java:31)
    at junit.framework.TestCase.assertTrue(TestCase.java:201)
    at org.eclipse.e4.ui.tests.workbench.PartRenderingEngineTests.testBug334580_01(PartRenderingEngineTests.java:2290)

testRemoveGuiBug324228_2(org.eclipse.e4.ui.tests.workbench.PartRenderingEngineTests)
junit.framework.AssertionFailedError: expected:<PerspectiveImpl (perspectiveA) Context> but was:<PerspectiveImpl (perspectiveB) Context>
    at junit.framework.Assert.fail(Assert.java:57)
    at junit.framework.Assert.failNotEquals(Assert.java:329)
    at junit.framework.Assert.assertEquals(Assert.java:78)
    at junit.framework.Assert.assertEquals(Assert.java:86)
    at junit.framework.TestCase.assertEquals(TestCase.java:253)
    at org.eclipse.e4.ui.tests.workbench.PartRenderingEngineTests.testRemoveGuiBug324228_2(PartRenderingEngineTests.java:1149)

testRemoveGuiBug324228_3(org.eclipse.e4.ui.tests.workbench.PartRenderingEngineTests)
junit.framework.AssertionFailedError: expected:<PerspectiveImpl (perspectiveA) Context> but was:<PerspectiveImpl (perspectiveB) Context>
    at junit.framework.Assert.fail(Assert.java:57)
    at junit.framework.Assert.failNotEquals(Assert.java:329)
    at junit.framework.Assert.assertEquals(Assert.java:78)
    at junit.framework.Assert.assertEquals(Assert.java:86)
    at junit.framework.TestCase.assertEquals(TestCase.java:253)
    at org.eclipse.e4.ui.tests.workbench.PartRenderingEngineTests.testRemoveGuiBug324228_3(PartRenderingEngineTests.java:1208)

testBug327701(org.eclipse.e4.ui.tests.workbench.PartRenderingEngineTests)
junit.framework.AssertionFailedError: expected:<PerspectiveImplContext> but was:<null>
    at junit.framework.Assert.fail(Assert.java:57)
    at junit.framework.Assert.failNotEquals(Assert.java:329)
    at junit.framework.Assert.assertEquals(Assert.java:78)
    at junit.framework.Assert.assertEquals(Assert.java:86)
    at junit.framework.TestCase.assertEquals(TestCase.java:253)
    at org.eclipse.e4.ui.tests.workbench.PartRenderingEngineTests.testBug327701(PartRenderingEngineTests.java:1440)

testRemoveGui_Bug332163(org.eclipse.e4.ui.tests.workbench.PartRenderingEngineTests)
junit.framework.AssertionFailedError: expected:<PerspectiveImplContext> but was:<PerspectiveImplContext>
    at junit.framework.Assert.fail(Assert.java:57)
    at junit.framework.Assert.failNotEquals(Assert.java:329)
    at junit.framework.Assert.assertEquals(Assert.java:78)
    at junit.framework.Assert.assertEquals(Assert.java:86)
    at junit.framework.TestCase.assertEquals(TestCase.java:253)
    at org.eclipse.e4.ui.tests.workbench.PartRenderingEngineTests.testRemoveGui_Bug332163(PartRenderingEngineTests.java:1725)
Comment 19 Eclipse Genie CLA 2015-04-10 21:41:32 EDT
New Gerrit change created: https://git.eclipse.org/r/45688
Comment 21 Brian de Alwis CLA 2015-04-10 21:59:40 EDT
Dirk, I backed out the change to LazyStackRenderer as it was resulting in test failures and doesn't seem necessary with your E4 translation test case.
Comment 22 Dirk Fauth CLA 2015-04-11 12:51:56 EDT
(In reply to Brian de Alwis from comment #21)
> Dirk, I backed out the change to LazyStackRenderer as it was resulting in
> test failures and doesn't seem necessary with your E4 translation test case.

Hi Brian,

thanks for looking into this. I just pulled the latest changes and can confirm that with your modification the translation still works as intended by my initial bugfix.

Greez,
Dirk

P.S. Shouldn't you update the copyright headers too?
Comment 23 Dirk Fauth CLA 2015-04-28 16:09:20 EDT
Tested with my example application https://github.com/fipro78/e4translationexample and it looks good.
Comment 24 Dirk Fauth CLA 2015-04-28 16:09:53 EDT
Tested with Eclipse 4.5.0 Integration Build: I20150428-0100 and it looks good.