Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » NPE in HandledContributionItem when testing application on eclipse 4.5
NPE in HandledContributionItem when testing application on eclipse 4.5 [message #1705721] Tue, 18 August 2015 14:45 Go to next message
Arne Deutsch is currently offline Arne DeutschFriend
Messages: 12
Registered: July 2009
Junior Member
I build some plugins on top of eclipse and testing with SWTBot. So far with eclipse 4.3.2 everything has worked. Now I try to update eclipse to 4.5. My applicaiton is running and everything works as expected. But my tests stop working. It seem to be related to the context menus I do register.

The reason seem to be that this line

final IEclipseContext lclContext = getContext(model);


resolves null. When debugging deeper I can see that the "eContainer" of the item is "null". Any idea how I can track down the reason? What is different when executing the application with SWTBot against when execute it manually? Because the context menus actually work as expected ...

I get this stack trace:

!ENTRY org.eclipse.ui 4 0 2015-08-18 16:36:00.843
!MESSAGE Unhandled event loop exception
!STACK 0
org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.NullPointerException)
	at org.eclipse.swt.SWT.error(SWT.java:4491)
	at org.eclipse.swt.SWT.error(SWT.java:4406)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4155)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3772)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
	at org.eclipse.swtbot.eclipse.core.UITestApplication.start(UITestApplication.java:57)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Caused by: java.lang.NullPointerException
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.canExecuteItem(HandledContributionItem.java:808)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:674)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:659)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:592)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1137)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1122)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:788)
	at org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot$2.run(AbstractSWTBot.java:166)
	at org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable$5.doRun(UIThreadRunnable.java:221)
	at org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable$1.run(UIThreadRunnable.java:89)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
	... 25 more


Thank you for any help you can provide!
Re: NPE in HandledContributionItem when testing application on eclipse 4.5 [message #1705781 is a reply to message #1705721] Wed, 19 August 2015 07:29 Go to previous messageGo to next message
Arne Deutsch is currently offline Arne DeutschFriend
Messages: 12
Registered: July 2009
Junior Member
Some more information after more debugging:

Inside "PartRenderingEngine" there is something called a "limbo" Shell (probably used for offscreen rendering). I can see there following comment:

// HACK!! we should loop until the display gets disposed...
// ...then we listen for the last 'main' window to get disposed
// and dispose the Display

And a bit later the following loop:

// Spin the event loop until someone disposes the display
while (((testShell != null && !testShell.isDisposed()) || (theApp != null && someAreVisible(theApp.getChildren()))) && !display.isDisposed()) {
	try {
		if (!display.readAndDispatch()) {
			runContext.processWaiting();
			if (spinOnce) {
				return;
			}
			advisor.eventLoopIdle(display);
		}
	} catch (ThreadDeath th) {
		throw th;
	} catch (Exception ex) {
		handle(ex, advisor);
	} catch (Error err) {
		handle(err, advisor);
	}
}


In addition there is some SWTBot code that disposes exactly this shell in "SWTBotShell":

public void close() throws TimeoutException {
	notify(SWT.Close);
	asyncExec(new VoidResult() {
		public void run() {
			// TODO investigate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=259895
			if (!widget.isDisposed())
				widget.close();
		}
	});
	new SWTBot().waitUntil(new DefaultCondition() {
		public boolean test() throws Exception {
			return !isOpen();
		}

		public String getFailureMessage() {
			return "Timed out waiting for " + SWTUtils.toString(widget) + " to close."; //$NON-NLS-1$ //$NON-NLS-2$
		}
	});
}


I can see it in this stack trace:
Thread [main] (Suspended (breakpoint at line 725 in Shell))	
	owns: RunnableLock  (id=6507)	
	Shell.dispose() line: 725	
	Shell(Decorations).closeWidget() line: 309	
	Shell.close() line: 538	
	SWTBotShell$2.run() line: 101	
	UIThreadRunnable$5.doRun() line: 221	
	UIThreadRunnable$1.run() line: 89	
	RunnableLock.run() line: 35	
	UISynchronizer(Synchronizer).runAsyncMessages(boolean) line: 135	
	Display.runAsyncMessages(boolean) line: 4155	
	Display.readAndDispatch() line: 3772	
	PartRenderingEngine$4.run() line: 1127	
	Realm.runWithDefault(Realm, Runnable) line: 337	
	PartRenderingEngine.run(MApplicationElement, IEclipseContext) line: 1018	
	E4Workbench.createAndRunUI(MApplicationElement) line: 156	
	Workbench$5.run() line: 654	
	Realm.runWithDefault(Realm, Runnable) line: 337	
	Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 598	
	PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 150	
	IDEApplication.start(IApplicationContext) line: 139	
	UITestApplication.start(IApplicationContext) line: 57	
	EclipseAppHandle.run(Object) line: 196	
	EclipseAppLauncher.runApplication(Object) line: 134	
	EclipseAppLauncher.start(Object) line: 104	
	EclipseStarter.run(Object) line: 380	
	EclipseStarter.run(String[], Runnable) line: 235	
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: 62	
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43	
	Method.invoke(Object, Object...) line: 497	
	Main.invokeFramework(String[], URL[]) line: 669	
	Main.basicRun(String[]) line: 608	
	Main.run(String[]) line: 1515	
	Main.main(String[]) line: 1488	


Not sure yet what is the root cause and the intention of this code ... every helpfull comment still appreciated Smile.
Re: NPE in HandledContributionItem when testing application on eclipse 4.5 [message #1705783 is a reply to message #1705781] Wed, 19 August 2015 07:51 Go to previous messageGo to next message
Arne Deutsch is currently offline Arne DeutschFriend
Messages: 12
Registered: July 2009
Junior Member
Finally I found and fixed the misbehaviour. I would classify it as an SWTBot bug. The problem was that my tests have called
SWTWorkbenchBot.resetWorkbench()

This in turn calls
SWTWorkbenchBot.closeAllShells()

This delegates to
DefaultWorkbench.closeAllShells()

Here this loop closes the "limbo" shell:
DefaultWorkbench closeAllShells() {
	SWTBotShell[] shells = bot.shells();
	for (SWTBotShell shell : shells) {
		if (!isEclipseShell(shell)) {
			shell.close();
		}
	}
	return this;
}

This loop uses the method "isEclipseShell" like this:
private boolean isEclipseShell(final SWTBotShell shell) {
	return getActiveWorkbenchWindowShell() == shell.widget;
}

I have put in my own bot in replacement for "SWTWorkbenchBot", duplicated all this code and basically replaced the last method with this:
private boolean isEclipseShell(final SWTBotShell shell) {
	return getActiveWorkbenchWindowShell() == shell.widget || "PartRenderingEngine's limbo".equals(shell.getText());
}

Now my tests start running again (not sure if they do run completly, but at least they can be started again Wink ).
Re: NPE in HandledContributionItem when testing application on eclipse 4.5 [message #1705790 is a reply to message #1705783] Wed, 19 August 2015 08:17 Go to previous message
Arne Deutsch is currently offline Arne DeutschFriend
Messages: 12
Registered: July 2009
Junior Member
I have commited a bug report: https://bugs.eclipse.org/bugs/show_bug.cgi?id=475346
Previous Topic:SWTBot executed in parallel?
Next Topic:Integrate SWTBOT test cases with Jenkins
Goto Forum:
  


Current Time: Fri Apr 19 23:32:03 GMT 2024

Powered by FUDForum. Page generated in 0.03441 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top