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

Bug 361672

Summary: InjectionException via NPE when starting a workspace with no perspective opened
Product: [Eclipse Project] Platform Reporter: Dean Roberts <dean.t.roberts>
Component: UIAssignee: Dean Roberts <dean.t.roberts>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: emoffatt, pwebster, remy.suen
Version: 4.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Dean Roberts CLA 2011-10-21 11:10:33 EDT
1) Start e4
2) Close all perspectives
3) Exit and save workpace
4) Restart e4

See InjectionEception/NPE

!ENTRY org.eclipse.e4.ui.workbench 4 0 2011-10-21 11:08:28.560
!MESSAGE Unable to create class 'org.eclipse.ui.internal.StandardTrim' from bundle '92'
!STACK 0
org.eclipse.e4.core.di.InjectionException: java.lang.NullPointerException
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
	at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:838)
	at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:110)
	at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:317)
	at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:252)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:177)
	at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:93)
	at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:64)
	at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:49)
	at org.eclipse.e4.ui.workbench.renderers.swt.ToolControlRenderer.createWidget(ToolControlRenderer.java:58)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:861)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:615)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:717)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$2(PartRenderingEngine.java:688)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$7.run(PartRenderingEngine.java:682)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:667)
	at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:59)
	at org.eclipse.e4.ui.workbench.renderers.swt.TrimBarRenderer.processContents(TrimBarRenderer.java:151)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:627)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$6.run(PartRenderingEngine.java:504)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:489)
	at org.eclipse.e4.ui.workbench.renderers.swt.WBWRenderer.processContents(WBWRenderer.java:591)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:627)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:717)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$2(PartRenderingEngine.java:688)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$7.run(PartRenderingEngine.java:682)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:667)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:933)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:888)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:90)
	at org.eclipse.ui.internal.Workbench$3.run(Workbench.java:565)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:520)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:352)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:618)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:624)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:579)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1431)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1407)
Caused by: java.lang.NullPointerException
	at org.eclipse.ui.internal.StandardTrim.createStatusLine(StandardTrim.java:81)
	at org.eclipse.ui.internal.StandardTrim.createWidget(StandardTrim.java:39)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:618)
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
	... 51 more
Comment 1 Dean Roberts CLA 2011-11-07 10:10:46 EST
When StandardTrim.createStatusLine() is called in the error case, the EclipseContext for the toolControl does not contain an IWorkbenchWindow.

While it would be trivial to do a null check, I'm not sure if this is just the symptom of a start up ordering problem?

The workbench window is being set in the context by WorkbenchWindow.setup().  But in the error case StandardTrim.createStatusLine() is called BEFORE WorkbnehcWindow.setup().

In a regular start up sequence, WorkbenchWindow.setup() is being called before StandardTrim.createStatusLine() so everything works.

In both cases, the startup sequence seems to be determined by PartRenderingEngine.createGui(MUIElement, Object, IEclipseContext) ... but I have not had much luck figuring out how this is intended to work.

I guess the question is, is this a start up ordering problem that needs to be fixed, or is it reasonable that the context may not have a workbench window set?
Comment 2 Remy Suen CLA 2011-11-08 09:09:51 EST
(In reply to comment #1)
> When StandardTrim.createStatusLine() is called in the error case, the
> EclipseContext for the toolControl does not contain an IWorkbenchWindow.

Ideally we should support the three controls that the current StandardTrim provides (progress bar, heap status, and a status line) in Eclipse 4. Also see bug 332499.

> I guess the question is, is this a start up ordering problem that needs to be
> fixed, or is it reasonable that the context may not have a workbench window
> set?

There's probably a startup ordering problem hidden in here but we should try to refactor those trim controls so that they don't need an IWorkbenchWindow to operate.
Comment 3 Dean Roberts CLA 2012-02-24 05:54:37 EST
A new Exception in this test case has been introduced, I believe by the work done in Bug 340695.  It looks like it is caused for the same reasons.

The Exception is an ArrayIndexOutOfBounds exception in ToolControlRenderer.createWidget()
Comment 4 Dean Roberts CLA 2012-02-24 06:23:32 EST
Fixed the NPE using the expedient Null check.  I believe modeling the progress bar, status line and heap size indicator will have to wait for a future release.  There is already a defect opened for this as noted in comment #2.

http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=6f4d44ec72636119320edd56e5495a5a05af4ed4

As noted in comment #3 there is now an ArrayIndexOutOfBoundsException that was introduced by work on trim dragging.

Since the cause seems slightly more involved than this one, and the trim drag work is ongoing, I have annotated that defect and will close this one.