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

Bug 370214

Summary: Throw Exception in @PostContruct leads to org.eclipse.e4.core.di.InjectionException: Unable to process "WorkbenchStatusReporter.shellProvider"
Product: [Eclipse Project] Platform Reporter: Lars Vogel <Lars.Vogel>
Component: UIAssignee: Oleg Besedin <ob1.eclipse>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Lars.Vogel, ob1.eclipse, pwebster
Version: 4.2   
Target Milestone: 4.2 M6   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Example Project none

Description Lars Vogel CLA 2012-01-31 08:19:33 EST
If I throw an UnsupportedOperationException in @PostContruct I get the following error: 

org.eclipse.e4.core.di.InjectionException: Unable to process "WorkbenchStatusReporter.shellProvider": 

This is really bad as it makes it very hard to find the cause of the problem.


Here is the example: 

@PostConstruct
	public void createControls(Composite parent) {
		Button button = new Button(parent, SWT.PUSH);
		button.setText("Delete Todo");
		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				throw new UnsupportedOperationException("not supported");
			}
		});

	}

Here is the full stacktace:

org.eclipse.e4.core.di.InjectionException: Unable to process "WorkbenchStatusReporter.shellProvider": no actual value was found for the argument "IShellProvider".
	at org.eclipse.e4.core.internal.di.InjectorImpl.reportUnresolvedArgument(InjectorImpl.java:387)
	at org.eclipse.e4.core.internal.di.InjectorImpl.resolveRequestorArgs(InjectorImpl.java:382)
	at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:99)
	at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:317)
	at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:239)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:153)
	at org.eclipse.e4.ui.internal.workbench.swt.StatusReporterCreationFunction.compute(StatusReporterCreationFunction.java:23)
	at org.eclipse.e4.core.internal.contexts.ValueComputation.get(ValueComputation.java:59)
	at org.eclipse.e4.core.internal.contexts.EclipseContext.internalGet(EclipseContext.java:220)
	at org.eclipse.e4.core.internal.contexts.EclipseContext.internalGet(EclipseContext.java:229)
	at org.eclipse.e4.core.internal.contexts.EclipseContext.get(EclipseContext.java:191)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9$1.eventLoopException(PartRenderingEngine.java:981)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.handle(PartRenderingEngine.java:1020)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1008)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:893)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:85)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:140)
	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:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:616)
	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:1433)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1409)
Comment 1 Oleg Besedin CLA 2012-01-31 11:01:10 EST
Could you attach complete code to duplicate the problem? I am not sure how the code piece in the comment 0 could create that error stack.
Comment 2 Lars Vogel CLA 2012-01-31 11:09:59 EST
@Oleg, strange isn't it? 

Here is the full implementation of the Part. There is not more execution code then then coding I originally attached.


package com.example.e4.rcp.todo.parts;

import javax.annotation.PostConstruct;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

public class TestPart {

	@PostConstruct
	public void createControls(Composite parent) {
		Button button = new Button(parent, SWT.PUSH);
		button.setText("Delete Todo");
		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				throw new UnsupportedOperationException("not supported");
			}
		});

	}
}
Comment 3 Lars Vogel CLA 2012-01-31 16:54:00 EST
Created attachment 210340 [details]
Example Project

As suggested a complete example project
Comment 4 Oleg Besedin CLA 2012-02-01 11:00:22 EST
The problem is that error reporting from a part renderer is broken. It tries to create WorkbenchStatusReporter using application context which does not have IShellProvider in it. Hence the error message you see - it is not the original error, but the error in creating error handling object. If that makes any sense. 

I added code into the WorkbenchStatusReporter to get a proper shell:

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

More generally, we need to cleanup IShellProvider service. Opened bug 370341 for that.
Comment 5 Oleg Besedin CLA 2012-02-01 11:00:39 EST
.
Comment 6 Lars Vogel CLA 2012-02-01 11:19:40 EST
Thanks for the fast fix.
Comment 7 Oleg Besedin CLA 2012-03-13 13:46:46 EDT
Verified in I20120313-0610.