Hi Cristiano,

That exception means that you are trying to use a bundle context which is no 
longer valid because the bundle has been stopped.

There are all sorts of ways that code can end up hanging on to a Bundle Context 
when it shouldn't, and it may be caused by something as simple as a race 
condition on shutdown, all the way through to a completely invalid design.

My advice would be not to use the BundleContext or a Bundle Activator in your 
code at all, and to use a framework like DS instead. DS will a manage the 
lifecycle of your components so that you don't need to use a BundleContext at 
all.

Best Regards,

Tim Ward

OSGi Alliance IoT EG Chair

> On 30 Jun 2016, at 15:57, Cristiano Costantini 
> <[email protected]> wrote:
> 
> Hello All,
> 
> I'n our application it happen sometime to find in situations where we get the 
> "Invalid BundleContext" exception:
> 
> java.lang.IllegalStateException: Invalid BundleContext. 
> at 
> org.apache.felix.framework.BundleContextImpl.checkValidity(BundleContextImpl.java:453)
> 
> What are the potential reasons such exception may be thrown?
> I'm searching to understand so I can hunt for a potential design issue in 
> some of our bundles... I've searched the web but I've found no hint.
> 
> Thank you!
> Cristiano
> 

Reply via email to