Hi,

On 13.07.2010 10:57, Tamas_Paulo wrote:
> 
> Hi all,
> 
> I faced a curious problem, when trying to use ConfigurationAdmin using the
> two below approaches I get different results, the first one works (sometimes
> it tries to get service too early, but otherwise OK). But with the second
> one I get NullPointerException on this line (stack trace below):
>               Configuration configuration = 
> m_configAdmin.getConfiguration(testPid);
> What is the difference between the two, am I doing something wrong?
> 
> 
> 1.)
>               m_configAdmin = (ConfigurationAdmin)
> m_bundleContext.getService(m_bundleContext
>                               
> .getServiceReference(ConfigurationAdmin.class.getName()));
> ---------------------------------------------------------------------------------------------
> 2.)
>               ServiceTracker tracker = new ServiceTracker(m_bundleContext, 
>                               ConfigurationAdmin.class.getName(), null);
>               tracker.open();
>               m_configAdmin = 
> (ConfigurationAdmin)tracker.waitForService(2000);
>               tracker.close();
> 
> Relevant part of stack trace:
> java.lang.NullPointerException
>       at
> org.apache.felix.cm.impl.ConfigurationAdminImpl.getConfiguration(ConfigurationAdminImpl.java:93)
>         at "my call"

I think, the gotcha is the "tracker.close()" call. This closes the
tracker and releases (ungets) all services. In the case of the Felix
ConfigurationAdmin service this causes the ConfigurationAdminImpl object
(assigned to the m_configAdmin field) to be disposed, i.e. unusable.
This causes the NullPointerException.

Thus, the fix here is to not call the ServiceTracker.close() method
before you use the service.

Regards
Felix


> 
> Thanks in advance:
> Tamás


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to