Community
Participate
Working Groups
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(); }
(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?
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.]
Would you be able to attach this as a patch? http://wiki.eclipse.org/Platform_UI/How_to_Contribute
Remy is now responsible for watching the [ViewMgmt] category.
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.