I created one plugin with the "Eclipse E4 Application Project" wizard, then added a second plugin with a model Fragment which contributes a Part to the one PartStack of the E4 application.
For this I followed http://www.vogella.com/articles/Eclipse4Modularity/article.html : Set ID of PartStack in the original Application.e4xmi, then define fragment.xmi that adds a Part to the PartStack.
All works fine when executed for the first time, or executed with a new workspace (by adding "-clearPersistedState" to the program arguments). But when starting the application with an existing workspace that contains the persisted workbench.xmi, there is this error message:
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.e4.ui.workbench.swt".
java.lang.NullPointerException
at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer.showTab(LazyStackRenderer.java:156)
at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.showTab(StackRenderer.java:1024)
at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer.postProcess(LazyStackRenderer.java:98)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:639)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:725)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$2(PartRenderingEngine.java:696)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$7.run(PartRenderingEngine.java:690)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:675)
Debugging into LazyStackRenderer.java:156 indicates that a getParent() call returns null.
The problem seems to originate from re-loading the persisted workbench.xmi, which includes this section (XML less-than etc. removed):
...children xsi:type="basic:PartStack" xmi:id="..." elementId="demo.app.mainstack" contributorURI="platform:/plugin/E4DemoApp" selectedElement="_MG5SoMbxEeGKj8gOLKAMgw"
....children xsi:type="basic:Part" xmi:id="_MG5SoMbxEeGKj8gOLKAMgw" elementId="demo.app.added_part" contributorURI="..." contributionURI="bundleclass://..." label="Added Part"
Note that the 'selectedElement' of the PartStack points to its single child entry. When that model is loaded in E4Application.loadApplicationModel(), 'theApp' in there looks like this:
Window->Perspective->...->PartStackImpl->PartImpl
The PartImpl.eContainer points back to the PartStackImpl. OK.
The PartStackImpl.selectedElement should in turn refer to the single enclosed PartImpl. Instead, it refers to a different PartImpl, an object with the correct elementId, contributorURI and contributionURI, but null for an eContainer.
The persisted workbench.xmi elements are therefore loaded OK but the selectedElement pointers refer to incomplete copies of the actual model elements. Later on, the LazyStackRenderer uses the incomplete 'selectedElement' copy which has null for a parent (eContainer) and throws a NullPointerException.
Any idea how to fix this or work around it? This is for Eclipse 4.2 for RCP and RAP.