Bug 264426 - [ViewMgmt] NPE in PageBookView if no default page
Summary: [ViewMgmt] NPE in PageBookView if no default page
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4.1   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2009-02-10 16:46 EST by Jon Barrilleaux CLA
Modified: 2019-09-06 16:09 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jon Barrilleaux CLA 2009-02-10 16:46:21 EST
Build ID: M20080911-1700

Steps To Reproduce:
1.createDefaultPage() returns null
2.createPartControl() will throw NPE
3.


More information:
In createPartControl(), the defaultPageRec is being created even though the defaultPage is null.  Thus, when preparePage() is called the page rec is non-null but the page is null, which generates the exception.

==================

Partial stack trace......


java.lang.NullPointerException
	at org.eclipse.ui.part.PageBookView.preparePage(PageBookView.java:429)
	at org.eclipse.ui.part.PageBookView.createPartControl(PageBookView.java:475)
	at org.eclipse.ui.internal.ViewReference.createPartHelper(ViewReference.java:371)
	at org.eclipse.ui.internal.ViewReference.createPart(ViewReference.java:230)
	at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:594)


===============

Here is a code with a fix (has not been tested -- null checking seems to be pretty loosey goosey throughout and there may be other side effects)......

	/**
	 * The <code>PageBookView</code> implementation of this
	 * <code>IWorkbenchPart</code> method creates a <code>PageBook</code>
	 * control with its default page showing. Subclasses may extend.
	 */
	public void createPartControl(Composite parent) {

		// Create the page book.
		book = new PageBook(parent, SWT.NONE);

		// Create the default page rec.
		IPage defaultPage = createDefaultPage(book);
//>>>
if(defaultPage != null) {
		defaultPageRec = new PageRec(null, defaultPage);
		preparePage(defaultPageRec);

		// Show the default page
		showPageRec(defaultPageRec);
}
//<<<

		// Listen to part activation events.
		getSite().getPage().addPartListener(this);
		showBootstrapPart();
	}
Comment 1 Remy Suen CLA 2009-02-10 17:08:48 EST
(In reply to comment #0)
> Build ID: M20080911-1700
> 
> Steps To Reproduce:
> 1.createDefaultPage() returns null

The API does not state that null can be returned for createDefaultPage(PageBook) or that it will be handled appropriately. Do you have a use case in mind?
Comment 2 Jon Barrilleaux CLA 2009-02-10 17:28:03 EST
Parts of PageBookView check to see if the defaultPageRec is null, other parts do not.  Regardless of the use case it seems that part of the code was anticipating a null default page rec (presumably as a result of createDefaultPage() returning null).

As for the specific use case, I am using the PageBookView to show predefined pages, not ones generated on the fly in correspondence with some other part becoming active (i.e. just like PageBook, but in a view, which is what I was expecting from PageBookView but was rudely surprised to discover otherwise).  As such, createDefaultPage() simply returns null (i.e. no default page), and I return my first predefined view in getBootstrapPart().  By using getBootstrapPart() instead of createDefaultPage(, the first page is created using doCreatePage(), the same as for any other page, rather than making the default page some oddball special case with its own contorted creation code.

[IMHO It certainly seems that PageBookView was architected with a very specific use case in mind, which makes it rather difficult to use in any other context, and is inconsistent with the notion of a PageBook, upon which it is built.  Also, the API jumps all over the place -- sometimes using page, sometimes rec, sometimes part, so on and so forth.]
Comment 3 Boris Bokowski CLA 2009-02-10 17:54:04 EST
Would you be able to attach this as a patch? http://wiki.eclipse.org/Platform_UI/How_to_Contribute
Comment 4 Boris Bokowski CLA 2009-11-11 17:31:23 EST
Remy is now responsible for watching the [ViewMgmt] category.
Comment 5 Eclipse Webmaster CLA 2019-09-06 16:09:08 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.