Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

osgi.enroute.scheduler.simple.provider: NPE at startup when bundle with CronJob is started before scheduler bundle #70

Open
Amplifino opened this issue Oct 19, 2016 · 3 comments

Comments

@Amplifino
Copy link

At startup a NPE occurs in InterschedulerImpl at line 90 because the addSchedule method is called by SCR before the activate method.

A simple fix is to drop the activate method and initialize the ScheduledExecutorService at field declaration.

@bjhargrave
Copy link
Member

Can you please provide a full stack trace? This may be a thread safety issue where one thread calls activate which writes the executor field while another thread calls after which reads the executor field.

@Amplifino
Copy link
Author

It is not a thread issue, simply the fact that SCR calls the addSchedule before the activate for any existing CronJog services at component activation time. (I should have stressed that I am using the whiteboard approach for scheduling services).
Easy to reproduce if you stop and then start the scheduler bundle while you have CronJob Services with a valid CRON property.
Stack trace:
okt 19, 2016 3:14:19 PM osgi.enroute.scheduler.simple.provider.InternalSchedulerImpl addSchedule
SEVERE: Invalid cron expression 0 * * * * ? from {service.id=108, objectClass=[Ljava.lang.String;@1b934c2d, component.name=eu.vandevelde.playground.impl.CronSample, cron=0 * * * * ?, service.scope=bundle, component.id=61, service.bundleid=40}
java.lang.NullPointerException
at osgi.enroute.scheduler.simple.provider.InternalSchedulerImpl.after(InternalSchedulerImpl.java:90)
at osgi.enroute.scheduler.simple.provider.InternalSchedulerImpl.at(InternalSchedulerImpl.java:285)
at osgi.enroute.scheduler.simple.provider.InternalSchedulerImpl.schedule(InternalSchedulerImpl.java:211)
at osgi.enroute.scheduler.simple.provider.InternalSchedulerImpl.schedule(InternalSchedulerImpl.java:269)
at osgi.enroute.scheduler.simple.provider.InternalSchedulerImpl$Cron.(InternalSchedulerImpl.java:296)
at osgi.enroute.scheduler.simple.provider.InternalSchedulerImpl.addSchedule(InternalSchedulerImpl.java:317)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.felix.scr.impl.inject.BaseMethod.invokeMethod(BaseMethod.java:224)
at org.apache.felix.scr.impl.inject.BaseMethod.access$500(BaseMethod.java:39)
at org.apache.felix.scr.impl.inject.BaseMethod$Resolved.invoke(BaseMethod.java:617)
at org.apache.felix.scr.impl.inject.BaseMethod.invoke(BaseMethod.java:501)
at org.apache.felix.scr.impl.inject.BindMethod.invoke(BindMethod.java:655)
at org.apache.felix.scr.impl.manager.DependencyManager.doInvokeBindMethod(DependencyManager.java:1722)
at org.apache.felix.scr.impl.manager.DependencyManager.open(DependencyManager.java:1556)
at org.apache.felix.scr.impl.manager.SingleComponentManager.createImplementationObject(SingleComponentManager.java:260)
at org.apache.felix.scr.impl.manager.SingleComponentManager.createComponent(SingleComponentManager.java:108)
at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:906)
at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:879)
at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:748)
at org.apache.felix.scr.impl.manager.AbstractComponentManager.enableInternal(AbstractComponentManager.java:674)
at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:429)
at org.apache.felix.scr.impl.manager.ConfigurableComponentHolder.enableComponents(ConfigurableComponentHolder.java:657)
at org.apache.felix.scr.impl.BundleComponentActivator.initialEnable(BundleComponentActivator.java:341)
at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:403)
at org.apache.felix.scr.impl.Activator.access$200(Activator.java:54)
at org.apache.felix.scr.impl.Activator$ScrExtension.start(Activator.java:278)
at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:259)
at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:232)
at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:482)
at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:415)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232)
at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:444)
at org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:913)
at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:834)
at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:516)
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4544)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2166)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:977)
at org.apache.felix.gogo.command.Basic.start(Basic.java:739)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.felix.gogo.runtime.Reflective.invoke(Reflective.java:137)
at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:82)
at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480)
at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406)
at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:119)
at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94)
at org.apache.felix.gogo.shell.Console.run(Console.java:66)
at org.apache.felix.gogo.shell.Shell.console(Shell.java:212)
at org.apache.felix.gogo.shell.Shell.gosh(Shell.java:137)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.felix.gogo.runtime.Reflective.invoke(Reflective.java:137)
at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:82)
at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480)
at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406)
at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:119)
at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94)
at org.apache.felix.gogo.shell.Activator$StartShellJob.run(Activator.java:179)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

@bjhargrave
Copy link
Member

Thanks for the stacktrace. There is definitely a bug in that the bind methods depend upon state set by the activate method. And the bind methods can be called before the activate method.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants