NullPointerException when trying to load Atomfeed

Module: Atomfeed 1.0.12

System Version: OpenMRS Core 2.2 with Core at tags/2.2.0-20181112.082045-243.

I’m trying to add atomfeed to my server and getting the following error.

org.openmrs.module.ModuleException: Unable to start OpenMRS. Error thrown was: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'atomfeedController' defined in URL [jar:file:/home/tomcat7/.OpenMRS/.openmrs-lib-cache/atomfeed/atomfeed.jar!/org/openmrs/module/atomfeed/web/controller/AtomfeedController.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.openmrs.module.atomfeed.web.controller.AtomfeedController]: Constructor threw exception; nested exception is java.lang.NullPointerException
	at org.openmrs.web.WebDaemon.startOpenmrs(WebDaemon.java:65)
	at org.openmrs.web.Listener.contextInitialized(Listener.java:192)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
	at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1091)
	at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1980)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: javax.servlet.ServletException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'atomfeedController' defined in URL [jar:file:/home/tomcat7/.OpenMRS/.openmrs-lib-cache/atomfeed/atomfeed.jar!/org/openmrs/module/atomfeed/web/controller/AtomfeedController.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.openmrs.module.atomfeed.web.controller.AtomfeedController]: Constructor threw exception; nested exception is java.lang.NullPointerException
	at org.openmrs.web.Listener.startOpenmrs(Listener.java:259)
	at org.openmrs.web.WebDaemon$1.run(WebDaemon.java:42)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'atomfeedController' defined in URL [jar:file:/home/tomcat7/.OpenMRS/.openmrs-lib-cache/atomfeed/atomfeed.jar!/org/openmrs/module/atomfeed/web/controller/AtomfeedController.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.openmrs.module.atomfeed.web.controller.AtomfeedController]: Constructor threw exception; nested exception is java.lang.NullPointerException
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:275)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1131)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1034)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
	at org.openmrs.module.ModuleUtil.refreshApplicationContext(ModuleUtil.java:888)
	at org.openmrs.module.web.WebModuleUtil.refreshWAC(WebModuleUtil.java:847)
	at org.openmrs.web.Listener.performWebStartOfModules(Listener.java:632)
	at org.openmrs.web.Listener.performWebStartOfModules(Listener.java:612)
	at org.openmrs.web.Listener.startOpenmrs(Listener.java:251)
	... 1 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.openmrs.module.atomfeed.web.controller.AtomfeedController]: Constructor threw exception; nested exception is java.lang.NullPointerException
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122)
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:267)
	... 17 more
Caused by: java.lang.NullPointerException
	at org.openmrs.api.context.ServiceContext.getRegisteredComponents(ServiceContext.java:916)
	at org.openmrs.api.context.ServiceContext.getRegisteredComponents(ServiceContext.java:880)
	at org.openmrs.api.context.Context.getRegisteredComponents(Context.java:1193)
	at org.openmrs.module.atomfeed.api.utils.ContextUtils.getFirstRegisteredComponent(ContextUtils.java:38)
	at org.openmrs.module.atomfeed.api.utils.ContextUtils.getAtomFeedClientHelper(ContextUtils.java:22)
	at org.openmrs.module.atomfeed.web.controller.AtomfeedController.(AtomfeedController.java:35)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
	... 19 more

I’ve turned it off and on again. I tried removing OpenMRS completely (uninstalling the server, wiping the app data dir, and dropping the database) and reinstalling from scratch – didn’t help. I get this error regardless of whether I drop the omod in the modules/ directory or try to install it from the Admin UI.

The lines where the error occurs, ServiceContext.java:914-916 read

	private <T> Map<String, T> getRegisteredComponents(ApplicationContext context, Class<T> type) {
		Map<String, T> components = new HashMap<>();
		Map registeredComponents = context.getBeansOfType(type);

specifically the last line, which would indicate that the context getting passed in is null. It comes from ServiceContext.java:879-880, which is

	public <T> List<T> getRegisteredComponents(Class<T> type) {
		Map<String, T> m = getRegisteredComponents(applicationContext, type);

where applicationContext is a private field:

public class ServiceContext implements ApplicationContextAware {

	private ApplicationContext applicationContext;

To compound my confusion, loading atomfeed is working just fine on a different computer. The computer on which it is working is an SDK server. The computer on which I’m encountering this error is a Tomcat server, installed as a Debian bundle. I think that both are running the same version of OpenMRS Core.

Anyone have any ideas why applicationContext might not be defined at the time Atomfeed wants to use it? Any guidance about how to debug this would be very welcome.

When you say that “I think that both are running the same version of OpenMRS Core.”, it looks like you need to more than just guess.

Fair. Based on my understanding of the build process, they should be the same. I don’t know how to check the tag/commit/version of Core that’s installed in each case. Lemme get back to you on that.

Attn @mseaton @mogoodrich

Oh, interesting, so as it turns out they are running different versions.

It’s failing on 2.2.0 SNAPSHOT Build 5039d2

It’s working on 2.2.0 SNAPSHOT Build c75f3e

Would it be hard for you to just use the non snapshot version of openmrs core 2.2.0 on both servers?

Yeah, I think doing that is our next step, now that 2.2.0 is out :slight_smile:

This seems like a relatively new Atom Feed module (different than the one packaged with Bahmni?). This may be obvious, but do we know if this version has ever been run/tested in a non-SDK version of OpenMRS running Tomcat?

Take care, Mark

I have run it under tomcat without any errors.

Cool, thanks @dkayiwa!

@SolDevelo @mogoodrich So I’ve narrowed down this problem to where it tries to instantiate a local version of the EventFeedService in a controller. Is there a reason this service isn’t created as a bean elsewhere?

Hi @bistenes

as far as I know there is used the EventFeedService from the third-party library (https://github.com/ICT4H/atomfeed). I’m not sure but perhaps this could be a reason why there is used the “new” statement to create the EventFeedService.

If you think that could be replaced by using the bean feel free to create a ticket and make changes.

Hi @alalo Please I have an issue saving configuration file for Atomfeed (version 1.0.12) on OpenMRS Platform 2.0.5 (ReferenceApplication 2.6.1). It is deployed on Tomcat 9.0 running Java 1.8 on windows 10. From the log, it throws the following error:

ERROR - AtomfeedUtils.writeFeedConfigurationToJsonFile(109) |2019-06-18 17:35:31,001| C:\Program%20Files\Apache%20Software%20Foundation\Tomcat%209.0\webapps\openmrs\WEB-INF\classes\customAtomfeedConfig.json (The system cannot find the path specified)

Thank you in advance

1 Like

Hi @aeze

Thank you for your feedback. The mentioned path should point to your custom configuration of the AtomFeed module. On Linux it is: /usr/local/tomcat/webapps/openmrs/WEB-INF/classes

This could be some kind of issue related to the Windows OS or the version of the Tomcat server. Currently, I couldn’t investigate what exactly goes wrong. Kindly create a ticket on the Sync dashboard (https://issues.openmrs.org/projects/SYNCT/issues) and describe the issue.

The workaround for you. Please try to use the docker version of reference application. More information you can find here:

Ok. Thank you so much