Author: tjwatson
Date: Thu Feb 7 21:31:44 2019
New Revision: 1853160
URL: http://svn.apache.org/viewvc?rev=1853160&view=rev
Log:
WORKING - fix NPE on ServiceRef.getBundle
Modified:
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/RegionConfigurationSupport.java
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/runtime/ServiceComponentRuntimeImpl.java
Modified:
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
URL:
http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java?rev=1853160&r1=1853159&r2=1853160&view=diff
==============================================================================
---
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
(original)
+++
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
Thu Feb 7 21:31:44 2019
@@ -757,9 +757,11 @@ public class BundleComponentActivator im
public RegionConfigurationSupport
setRegionConfigurationSupport(ServiceReference<ConfigurationAdmin> reference)
{
RegionConfigurationSupport rcs =
m_componentRegistry.registerRegionConfigurationSupport( reference );
- for ( ComponentHolder<?> holder : m_holders )
- {
- rcs.configureComponentHolder( holder );
+ if (rcs != null) {
+ for ( ComponentHolder<?> holder : m_holders )
+ {
+ rcs.configureComponentHolder( holder );
+ }
}
return rcs;
}
Modified:
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
URL:
http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java?rev=1853160&r1=1853159&r2=1853160&view=diff
==============================================================================
---
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
(original)
+++
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
Thu Feb 7 21:31:44 2019
@@ -640,7 +640,11 @@ public class ComponentRegistry
public RegionConfigurationSupport registerRegionConfigurationSupport(
ServiceReference<ConfigurationAdmin> reference) {
- RegionConfigurationSupport trialRcs = new
RegionConfigurationSupport(m_logger, reference) {
+ Bundle bundle = reference.getBundle();
+ if (bundle == null) {
+ return null;
+ }
+ RegionConfigurationSupport trialRcs = new
RegionConfigurationSupport(m_logger, reference, bundle) {
@Override
protected Collection<ComponentHolder<?>>
getComponentHolders(TargetedPID pid)
{
Modified:
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/RegionConfigurationSupport.java
URL:
http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/RegionConfigurationSupport.java?rev=1853160&r1=1853159&r2=1853160&view=diff
==============================================================================
---
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/RegionConfigurationSupport.java
(original)
+++
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/RegionConfigurationSupport.java
Thu Feb 7 21:31:44 2019
@@ -69,11 +69,10 @@ public abstract class RegionConfiguratio
* @param bundleContext of the ConfigurationAdmin we are tracking
* @param registry
*/
- public RegionConfigurationSupport(final ScrLogger logger, final
ServiceReference<ConfigurationAdmin> reference)
+ public RegionConfigurationSupport(final ScrLogger logger, final
ServiceReference<ConfigurationAdmin> reference, Bundle bundle)
{
this.logger = logger;
this.caReference = reference;
- final Bundle bundle = reference.getBundle();
this.bundleId = bundle.getBundleId();
this.caBundleContext = bundle.getBundleContext();
}
Modified:
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/runtime/ServiceComponentRuntimeImpl.java
URL:
http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/runtime/ServiceComponentRuntimeImpl.java?rev=1853160&r1=1853159&r2=1853160&view=diff
==============================================================================
---
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/runtime/ServiceComponentRuntimeImpl.java
(original)
+++
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/runtime/ServiceComponentRuntimeImpl.java
Thu Feb 7 21:31:44 2019
@@ -288,7 +288,11 @@ public class ServiceComponentRuntimeImpl
{
if (serviceRef == null)
return null;
- final long bundleId = serviceRef.getBundle().getBundleId();
+ final Bundle bundle = serviceRef.getBundle();
+ if (bundle == null) {
+ return null;
+ }
+ final long bundleId = bundle.getBundleId();
ConcurrentHashMap<Long, ServiceReferenceDTO[]> cache = dtoCache.get();
if (cache == null) {
cache = new ConcurrentHashMap<>();
@@ -296,7 +300,7 @@ public class ServiceComponentRuntimeImpl
}
ServiceReferenceDTO[] dtos = cache.get(bundleId);
if (dtos == null) {
- dtos = serviceRef.getBundle().adapt(ServiceReferenceDTO[].class);
+ dtos = bundle.adapt(ServiceReferenceDTO[].class);
if (dtos == null) {
dtos = new ServiceReferenceDTO[0];
}
@@ -488,7 +492,9 @@ public class ServiceComponentRuntimeImpl
ConcurrentHashMap<Long, ServiceReferenceDTO[]> cache =
dtoCache.get();
if (cache != null)
{
-
cache.remove(event.getServiceReference().getBundle().getBundleId());
+ // using bundle id property incase the service has gotten
unregistered
+ // before we could get the bundle object
+
cache.remove(event.getServiceReference().getProperty(Constants.SERVICE_BUNDLEID));
}
}
}