Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » npe in ModelServiceImpl (IEventBroker == null) when starting e4 application
npe in ModelServiceImpl (IEventBroker == null) when starting e4 application [message #1778374] Wed, 13 December 2017 14:33 Go to next message
Christian Eugster is currently offline Christian EugsterFriend
Messages: 203
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
Hi
I work on an eclipse e4 rcp (my first as far). I think I understand most of the concepts roughly. After search long time for a solution in the web (eclipse e4 forum too) without finding any, I try it here now:
When the application starts I get a null point exception that is located in the constructor of ModelServiceImpl:
		this.appContext = appContext;
		IEventBroker eventBroker = appContext.get(IEventBroker.class);
		eventBroker.subscribe(UIEvents.UIElement.TOPIC_WIDGET, hostedElementHandler);

The stack trace says:
!ENTRY org.eclipse.osgi 4 0 2017-12-13 15:29:05.333
!MESSAGE Anwendungsfehler
!STACK 1
java.lang.NullPointerException
	at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.<init>(ModelServiceImpl.java:122)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createDefaultContext(E4Application.java:511)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createE4Workbench(E4Application.java:204)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:149)
	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:388)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1499)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1472)
Ein Fehler ist aufgetreten. Informationen hierzu enthält die Protokolldatei
/Users/christian/Projekte/ceugster/Entwicklung/herakles/runtime-ch.eugster.herakles.app/.metadata/.log.

The org. eclipse.e4.ui.services bundle, where the event broker resides (as I understood) is checked. All dependencies are resolved.
Does anybody have a hint where to look further?
Thank you very much!
Christian
Re: npe in ModelServiceImpl (IEventBroker == null) when starting e4 application [message #1778648 is a reply to message #1778374] Tue, 19 December 2017 10:18 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Have you configured org.eclipse.equinox.event to be autostarted in the product file?
Re: npe in ModelServiceImpl (IEventBroker == null) when starting e4 application [message #1778829 is a reply to message #1778648] Fri, 22 December 2017 09:59 Go to previous messageGo to next message
Christian Eugster is currently offline Christian EugsterFriend
Messages: 203
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
Hi Dirk, that was it, thank you very much! Christian
Re: npe in ModelServiceImpl (IEventBroker == null) when starting e4 application [message #1784056 is a reply to message #1778648] Thu, 22 March 2018 01:20 Go to previous messageGo to next message
David Poxon is currently offline David PoxonFriend
Messages: 5
Registered: March 2018
Junior Member
I am using Oxygen and new to RCP development. How do I configure the autostart? I have added org.eclipse.equinox.event to the Dependencies tab.
Re: npe in ModelServiceImpl (IEventBroker == null) when starting e4 application [message #1784141 is a reply to message #1784056] Thu, 22 March 2018 20:05 Go to previous messageGo to next message
Christian Eugster is currently offline Christian EugsterFriend
Messages: 203
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
In the run configuration for your app (go to bug icon, click and select "debug configurations...") In the new window select on the left side your application. then on the right side go to the tab "plugins". In the combo "launch with" select "plugins selected below only". Then find the bundle and set it to autostart in the respective column.
Christian

[Updated on: Thu, 22 March 2018 20:08]

Report message to a moderator

Re: npe in ModelServiceImpl (IEventBroker == null) when starting e4 application [message #1784153 is a reply to message #1784141] Fri, 23 March 2018 00:31 Go to previous messageGo to next message
David Poxon is currently offline David PoxonFriend
Messages: 5
Registered: March 2018
Junior Member
Autostart for org.eclipse.equinox.event was set to 'default', and I set it to 'true'. However, I'm still seeing the same error. :/
Re: npe in ModelServiceImpl (IEventBroker == null) when starting e4 application [message #1784175 is a reply to message #1784153] Fri, 23 March 2018 08:51 Go to previous messageGo to next message
Christian Eugster is currently offline Christian EugsterFriend
Messages: 203
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
Hi David
Where do you inject the event broker? (you should not inject it e.g. in the lifecycles @PostContextCreate method, because there event broker is not yet available.
Christian

[Updated on: Fri, 23 March 2018 09:08]

Report message to a moderator

Re: npe in ModelServiceImpl (IEventBroker == null) when starting e4 application [message #1784272 is a reply to message #1784175] Mon, 26 March 2018 00:31 Go to previous messageGo to next message
David Poxon is currently offline David PoxonFriend
Messages: 5
Registered: March 2018
Junior Member
Hi Christian,
Sorry for the delay in reply - sadly, I don't know enough about this type of project to give you an answer. I have inherited this project from someone else, and this type of project is completely new to me.
Thanks, David
Re: npe in ModelServiceImpl (IEventBroker == null) when starting e4 application [message #1784303 is a reply to message #1784272] Mon, 26 March 2018 12:31 Go to previous messageGo to next message
Christian Eugster is currently offline Christian EugsterFriend
Messages: 203
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
HI David
then I recommend that you read the book about developing e4 apps: http://www.vogella.com/books/eclipsercp.html
Have a nice day.
Christian
Re: npe in ModelServiceImpl (IEventBroker == null) when starting e4 application [message #1784317 is a reply to message #1784153] Mon, 26 March 2018 16:48 Go to previous messageGo to next message
Glenn Burkhardt is currently offline Glenn BurkhardtFriend
Messages: 12
Registered: April 2017
Junior Member
We started seeing this problem, too, after upgrading to Eclipse 4.7.3. Turning autostart to 'true' in the run configuration didn't work for me, either, but deleting the run configuration, and changing the product definition to turn autostart on for "org.eclipse.equinox.event", and re-creating the run configuration, did.

index.php/fa/32449/0/
  • Attachment: Capture.PNG
    (Size: 14.44KB, Downloaded 2155 times)
Re: npe in ModelServiceImpl (IEventBroker == null) when starting e4 application [message #1784332 is a reply to message #1784303] Tue, 27 March 2018 00:59 Go to previous messageGo to next message
David Poxon is currently offline David PoxonFriend
Messages: 5
Registered: March 2018
Junior Member
Hi Christian,
Thank you, I will do that!
David
Re: npe in ModelServiceImpl (IEventBroker == null) when starting e4 application [message #1784333 is a reply to message #1784317] Tue, 27 March 2018 01:01 Go to previous messageGo to next message
David Poxon is currently offline David PoxonFriend
Messages: 5
Registered: March 2018
Junior Member
Glenn,
Thank you, this solved my issue!
David
Re: npe in ModelServiceImpl (IEventBroker == null) when starting e4 application [message #1784736 is a reply to message #1784333] Tue, 03 April 2018 11:28 Go to previous messageGo to next message
Mike Rumpf is currently offline Mike RumpfFriend
Messages: 47
Registered: July 2009
Member
Still this feels like a bug. If the event admin bundle becomes active later than this code is executed (which may happen) there will always be a NPE.

OSGi services can come and go anytime...

The error message also could be improved on...

Regards,
Mike
Re: npe in ModelServiceImpl (IEventBroker == null) when starting e4 application [message #1784761 is a reply to message #1784736] Tue, 03 April 2018 17:19 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
In general you are right. But E4 has a strong dependency on EventAdmin on startup. And even in other big osgi applications the EventAdmin is a service that is not intended to come and go at any time. The whole application model is dependent on it, do removing it at runtime would mean to stop the application.

The problem is that we cannot define that mandatory dependency reliably.
Re: npe in ModelServiceImpl (IEventBroker == null) when starting e4 application [message #1784770 is a reply to message #1784761] Tue, 03 April 2018 19:38 Go to previous messageGo to next message
Mike Rumpf is currently offline Mike RumpfFriend
Messages: 47
Registered: July 2009
Member
But isn't it still a problem? How can you make sure the EventAdmin is started earlier than the application model? There is no guarantee as far as I know. Of course you could mingle with the start levels but that is also considered "bad practise". Or do I miss something?
Re: npe in ModelServiceImpl (IEventBroker == null) when starting e4 application [message #1784771 is a reply to message #1784770] Tue, 03 April 2018 20:09 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
In plain OSGi it is considered bad practice. But in E4 with Equinox I would not know an alternative. The EventAdmin interface is not in org.eclipse.equinox.event. So actually nobody refers to a class in that bundle which would start it. Same is true for DS. And as Equinox has a lazy bundle loading policy, these bundles as well as the simple configurator bundle need to be autostarted. In Apache Felix you can configure this, where typically all bundles are auto started. Currently I am not 100% sure how Felix ensures that DS and EventAdmin are started early. It is either the launcher or the fact that the dependencies are well defined via capabilities and through the autostart the startup order is correct.

Maybe it also helps to use the ServiceTracker internally instead of ServiceReference. But that needs to be evaluated clearly.
Re: npe in ModelServiceImpl (IEventBroker == null) when starting e4 application [message #1785582 is a reply to message #1784771] Tue, 17 April 2018 07:35 Go to previous messageGo to next message
Mike Rumpf is currently offline Mike RumpfFriend
Messages: 47
Registered: July 2009
Member
Wouldn't it be possible to launch the E4 application from a service component? Then you could depend on EventAdmin and other services which are needed. The "start up" component would just wait for the relevant service. But I guess that is not feasible in the E4 world because of downward compatibility or other issues.
Re: npe in ModelServiceImpl (IEventBroker == null) when starting e4 application [message #1785584 is a reply to message #1785582] Tue, 17 April 2018 07:53 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
In a plain OSGi with DS world that would be a solution. Not sure which implications that would bring in with regards to the whole startup process. But we could consider this for the future.

For the moment I solved that issue by registering the EventHandler via whiteboard pattern instead of using the EventBroker. This way the startup order dependency to EventAdmin is gone. It has some implications for frameworks like RAP that need to align with the fact that the ModelServiceImpl is now created via ContextInjectionFactory for being able to unregister the handler on context destroyal. But that should not be a major issue from what I have heard so far.
Previous Topic:How to get rid of the Minimize ans Maximize buttons
Next Topic:How to auto start command ?
Goto Forum:
  


Current Time: Wed Apr 24 15:10:13 GMT 2024

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

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

Back to the top