Error: NPE When Running Atomfeed Module on Openmrs 1.11.x

So I want to test the sync 2.0 functionality on OpenMRS 1.11.x (As the module is specified to be compatible with 1.11.3). Among other modules it requires Atomfeed 1.0.12. Unfortunately running the module throws the following exception.

ERROR - Listener.contextInitialized(188) |2019-06-19 11:36:41,386| Got exception while starting up:
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:/private/var/folders/y4/v_dwgzq17hd5tbmyqbq7w8dh0000gp/T/1560962187119.openmrs-lib-cache/atomfeed/atomfeed.jar!/org/openmrs/module/atomfeed/web/controller/AtomfeedController.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.openmrs.module.atomfeed.web.controller.AtomfeedController]: Constructor threw exception; nested exception is java.lang.NullPointerException
	at org.openmrs.web.WebDaemon.startOpenmrs(WebDaemon.java:64)
	at org.openmrs.web.Listener.contextInitialized(Listener.java:180)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5077)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5591)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: javax.servlet.ServletException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'atomfeedController' defined in URL [jar:file:/private/var/folders/y4/v_dwgzq17hd5tbmyqbq7w8dh0000gp/T/1560962187119.openmrs-lib-cache/atomfeed/atomfeed.jar!/org/openmrs/module/atomfeed/web/controller/AtomfeedController.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.openmrs.module.atomfeed.web.controller.AtomfeedController]: Constructor threw exception; nested exception is java.lang.NullPointerException
	at org.openmrs.web.Listener.startOpenmrs(Listener.java:257)
	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:/private/var/folders/y4/v_dwgzq17hd5tbmyqbq7w8dh0000gp/T/1560962187119.openmrs-lib-cache/atomfeed/atomfeed.jar!/org/openmrs/module/atomfeed/web/controller/AtomfeedController.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [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:288)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1075)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:979)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
	at org.openmrs.module.ModuleUtil.refreshApplicationContext(ModuleUtil.java:837)
	at org.openmrs.module.web.WebModuleUtil.refreshWAC(WebModuleUtil.java:962)
	at org.openmrs.web.Listener.performWebStartOfModules(Listener.java:627)
	at org.openmrs.web.Listener.performWebStartOfModules(Listener.java:606)
	at org.openmrs.web.Listener.startOpenmrs(Listener.java:249)
	... 1 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [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:121)
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:280)
	... 17 more
Caused by: java.lang.NullPointerException
	at org.openmrs.api.context.ServiceContext.getRegisteredComponents(ServiceContext.java:986)
	at org.openmrs.api.context.ServiceContext.getRegisteredComponents(ServiceContext.java:950)
	at org.openmrs.api.context.Context.getRegisteredComponents(Context.java:1280)
	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.<init>(AtomfeedController.java:35)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
	... 19 more

Examining the above stacktrace indicates that this line is the culprit. Looking at this xml bean initialization code I don’t see how the applicationContext property is set. I even went hunting for any call to ServiceContext.setApplicationContext() in the code base without success.

At this point I am not sure what I am dealing with here. Could someone who understand this point me to the right direction?

Also if there is any workaround to avoid this problem I am more than happy to listen.

Environment

Openmrs: v1.11.6 running using Openmrs SDK

Atomfeed: v1.0.12

Java: 1.7

Tomcat7

It looks like this might be one of the issues referred to by this issue.

I am going to run against the master branch.

Update

The master build works for now. I haven’t tested the feeds themselves yet though.

Thank you. Solved my issue too.

1 Like