Bug 475154 - NullPointerException in PartServiceImpl.switchPerspective() when switching perspective while active view placed inside editors area
Summary: NullPointerException in PartServiceImpl.switchPerspective() when switching pe...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.6   Edit
Hardware: PC Windows 7
: P2 normal (vote)
Target Milestone: 4.7.1   Edit
Assignee: Brian de Alwis CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-17 09:30 EDT by Yurii Polek CLA
Modified: 2021-03-08 09:19 EST (History)
2 users (show)

See Also:


Attachments
Example app (112.37 KB, application/octet-stream)
2015-08-17 09:30 EDT, Yurii Polek CLA
no flags Details
Log with stacktrace (4.35 KB, text/plain)
2015-08-17 09:33 EDT, Yurii Polek CLA
no flags Details
null check patch (969 bytes, patch)
2015-08-19 10:32 EDT, Yurii Polek CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yurii Polek CLA 2015-08-17 09:30:19 EDT
Created attachment 255897 [details]
Example app

PartServiceImpl.switchPerspective() fails to activate part when active view was docked into editors area. Exception is thrown:
java.lang.NullPointerException
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.switchPerspective(PartServiceImpl.java:590)
	at org.eclipse.e4.ui.workbench.renderers.swt.PerspectiveStackRenderer.showTab(PerspectiveStackRenderer.java:127)
        ...

Steps to reproduce:
1. Launch example app from attachment.
2. Drag&Drop Message view to editors area (area below view).
3. Switch perspective.
4. Activate Message view.
5. Switch perspective to previous one.
6. Activate Message view.
7. Switch perspective.
Result: NPE in log.
Comment 1 Yurii Polek CLA 2015-08-17 09:33:22 EDT
Created attachment 255898 [details]
Log with stacktrace
Comment 2 Yurii Polek CLA 2015-08-19 10:32:15 EDT
Created attachment 255954 [details]
null check patch

fixes NullPointerException by adding null check
Comment 3 Yurii Polek CLA 2015-08-19 10:32:34 EDT
In can see two possible causes of NPE in this scenario:
1) partActivationHistory.isValid(perspective, activePart) in PartServiceImpl#switchPerspective(MPerspective)
returns false for part which was moved to editors area.
It is because part's placeholder is hidden (toBeRendered = false) during perspective switch in method WorkbenchPage.setPerspective(IPerspectiveDescriptor) by line modelService.hideLocalPlaceholders(window, modelPerspective). #hideLocalPlaceholders() iterates through all placeholders and hide local placeholder that have global counterpart. In case of example app Message view has both local and global placeholders, local is original added in PerspectiveFactory and global is in editors area added when view was moved to editors area.
I'm wondering if it is expected behaviour or #isValid() should return true in this case?

2) newActivePart.getParent() returns null because it's parent is TrimmedWindowImpl, and it does not pass below check:
if (eContainerFeatureID() != UiPackageImpl.UI_ELEMENT__PARENT) return null;
Here question is: is view moved into editors area has correct parent in application model?

Please, advise where workflow goes wrong?

If both suggestions are incorrect and it works as expected then NPE may be fixed by null check (patch attached).
Comment 4 Brian de Alwis CLA 2017-07-05 10:56:42 EDT
I came across this bug report from the following AERI problem report:

   https://dev.eclipse.org/recommenders/committers/aeri/v2/#!/problems/5836b555e4b0a95537a8eeca

Although I'm unable to reproduce this with Yuri's steps in 4.7, we're continuing to get reports in AERI and Yuri's fix is the same that I had put together, and looks safe.
Comment 5 Eclipse Genie CLA 2017-07-05 10:57:09 EDT
New Gerrit change created: https://git.eclipse.org/r/100739
Comment 7 Eclipse Genie CLA 2017-08-09 21:34:28 EDT
New Gerrit change created: https://git.eclipse.org/r/102824
Comment 9 Brian de Alwis CLA 2017-08-10 11:57:59 EDT
Fixed in 4.7.1.
Comment 10 Dani Megert CLA 2017-08-15 10:44:20 EDT
(In reply to Brian de Alwis from comment #9)
> Fixed in 4.7.1.

Next time, please make sure to check whether the bundle version needs to be increased. Thanks.
Comment 11 Brian de Alwis CLA 2017-08-25 10:36:10 EDT
Verified by inspection in source.