Bug 566438 - WorkbenchPage: ViewReference handling of duplicate Parts seems wrong
Summary: WorkbenchPage: ViewReference handling of duplicate Parts seems wrong
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.16   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-27 05:03 EDT by Benedikt Kuntz CLA
Modified: 2021-06-04 00:55 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 Benedikt Kuntz CLA 2020-08-27 05:03:52 EDT
We have an e4 Application that still uses the legacy Workbench, mainly to use the Eclipse Help functionality.
In the application, one may have two parts of the same type in a part stack, i.e. the MParts have the same elementId. When the Help should be opened for the second part, DefaultHelpUI throws a NPE beacuse WorkbenchPage#getActivePart returns null.
After some investigation I found that the viewReferences handling in WorkbenchPage is the cause:
In addViewReference it is checked that the viewReferences list does not already contain an entry with the same elementId od the reference's MPart. Thus, my second part is not added to the viewReferences when opened.
When retrieving the ViewReferences in getViewReference(MPart), the check is for equivalence of the reference's MPart (ref.getModel() == part) instead of a check for the elementId. So, null is returned and the NPE is thrown in DefaultHelpUI.
If I change the MPart elementIds to something like old.id_1 and old.id_2, then the NPE is not thrown (of course having other unwanted implications...)
Comment 1 Lars Vogel CLA 2020-08-27 06:00:28 EDT
Sounds like  ViewReferences needs to check for the ID instead. Is this also your assessment, Benedikt?
Comment 2 Eclipse Genie CLA 2020-08-27 08:23:45 EDT
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.ui/+/168308
Comment 3 Benedikt Kuntz CLA 2020-08-27 08:25:05 EDT
(In reply to Lars Vogel from comment #1)
> Sounds like  ViewReferences needs to check for the ID instead. Is this also
> your assessment, Benedikt?

Well I am not too much into that Workbench handling, but I guess there should be one ViewReference for each MPart instance. If that's the case, then the contains-check in WorkbenchPage should also check for equality instead of the ID (like the getViewReference method). Otherwise there will always be only one ViewReference per ID.
I added a gerrit to show what I *think* is more correct... But I cannot really see what kind of other implications this could have.
Comment 4 Benedikt Kuntz CLA 2020-09-01 01:23:33 EDT
Lars, how should we proceed here? I am not really confident that we should merge the gerrit, it seems to me that this could have some unwanted implications. But on a pure logical basis, the fix seems correct to me...
Comment 5 Lars Vogel CLA 2020-09-01 02:13:26 EDT
(In reply to Benedikt Kuntz from comment #4)
> Lars, how should we proceed here? I am not really confident that we should
> merge the gerrit, it seems to me that this could have some unwanted
> implications. But on a pure logical basis, the fix seems correct to me...

Lets review for 4.18M1, 4.17 is in release freeze.
Comment 6 Lars Vogel CLA 2020-11-18 08:32:14 EST
Mass change to 4.19 M1, please update the target if you have other plans.
Comment 7 Alexander Kurtakov CLA 2021-01-07 03:07:57 EST
Mass move 4.19 M1 bugs to M3
Comment 8 Niraj Modi CLA 2021-02-19 07:59:03 EST
Removing milestone from 4.19 M3 to 4.19, please re-target accordingly.
Comment 9 Kalyan Prasad Tatavarthi CLA 2021-03-02 02:07:43 EST
Mass move out of 4.19
Comment 10 Mickael Istria CLA 2021-03-18 10:00:18 EDT
Do you think the root cause may be that the elementId is incorrect? I'm wondering whther this might be a deeper issue.
Comment 11 Benedikt Kuntz CLA 2021-03-18 10:18:52 EDT
Not sure what you mean with incorrect elementId? The id (in my case) comes from the e4 model (i have a part descriptor with id "xyz") that is added to a part stack one or more times.
I did not spot any other problems with the ViewReference handling except for the one mentioned before with the NPE in the DefaultHelpUI...
Comment 12 Mickael Istria CLA 2021-03-18 10:21:14 EDT
If I understand correctly, the problem is that 2 distinct view reference do share the same elementId, isn't it? If so, wouldn't it be instead expected that those have different elementId?
Comment 13 Benedikt Kuntz CLA 2021-03-18 10:44:50 EDT
Yes, I assume that is the problem. 
It is expected in the contains method of the class, but not in the getViewReference method.

I cannot say if they have to be different from the e4 point of view, but actually I guess not because I have never heard that you have to change the element ID manually during runtime...
Comment 14 Kalyan Prasad Tatavarthi CLA 2021-06-04 00:55:24 EDT
Mass Move out of 4.20