Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 365525

Summary: MinMax addon throws NPE when no perspective is available
Product: [Eclipse Project] Platform Reporter: Kai Toedter <kai.toedter>
Component: UIAssignee: Christoph Laeubrich <laeubi>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: laeubi, Lars.Vogel, ma.becker, remy.suen
Version: 4.2   
Target Milestone: 4.14 M1   
Hardware: PC   
OS: Windows 7   
See Also: https://git.eclipse.org/r/149942
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=7f617ce6fdb4be8f151d192ac1dadde271445913
Whiteboard:

Description Kai Toedter CLA 2011-12-04 11:03:19 EST
Perspectives are optional in the Workbench model. The MinMax addon throws an NPE, when no perspective is available. Fixes:

Project org.eclipse.e4.ui.workbench.addons.swt
Class MinMaxAddon.java

	private int getCachedIndex(MUIElement element) {
		MPerspective persp = modelService.getPerspectiveFor(element);
		if (persp == null)
			return -1;
...

	private SideValue getCachedBar(MUIElement element) {
		MPerspective persp = modelService.getPerspectiveFor(element);
		if (persp == null)
			return null;
...

I could commit that myself, but I would like Eric to review the fix :)
Comment 1 Remy Suen CLA 2011-12-04 17:52:27 EST
(In reply to comment #0)
>     private SideValue getCachedBar(MUIElement element) {
>         MPerspective persp = modelService.getPerspectiveFor(element);
>         if (persp == null)
>             return null;

Indeed, see bug 365192.

> I could commit that myself, but I would like Eric to review the fix :)

Eric, could you take a look at this?
Comment 2 Christoph Laeubrich CLA 2019-09-21 01:55:11 EDT
Even tough the code has changed in the past 8 years, the problem (and similar missing null checks) still persist. I'll provide a patch for this, would be good if someone can review it then.
Comment 3 Eclipse Genie CLA 2019-09-21 01:58:43 EDT
New Gerrit change created: https://git.eclipse.org/r/149942
Comment 4 Matthias Becker CLA 2019-09-23 03:25:23 EDT
(In reply to Kai Toedter from comment #0)
> Perspectives are optional in the Workbench model. The MinMax addon throws an
> NPE, when no perspective is available. Fixes:
> 
> Project org.eclipse.e4.ui.workbench.addons.swt
> Class MinMaxAddon.java
> 
> 	private int getCachedIndex(MUIElement element) {
> 		MPerspective persp = modelService.getPerspectiveFor(element);
> 		if (persp == null)
> 			return -1;
> ...
> 
> 	private SideValue getCachedBar(MUIElement element) {
> 		MPerspective persp = modelService.getPerspectiveFor(element);
> 		if (persp == null)
> 			return null;
> ...
> 
> I could commit that myself, but I would like Eric to review the fix :)

How can I reproduce this NPE? What steps do I need to perform?
Comment 6 Matthias Becker CLA 2019-09-25 02:54:13 EDT
Thanks Christoph for fixing this very old bug.