FELIX-5057 : Race condition between getService and stopping the http service
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1705725 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java b/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
index 773bf83..69790d3 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
@@ -115,13 +115,13 @@
public void stop()
{
- this.context = null;
if ( this.httpServiceReg != null )
{
this.httpServiceReg.unregister();
this.httpServiceReg = null;
}
+ this.context = null;
this.sharedHttpService = null;
this.contextAttributeListenerManager.close();
@@ -134,13 +134,17 @@
@Override
public HttpService getService(final Bundle bundle, final ServiceRegistration<HttpService> reg)
{
- return new PerBundleHttpServiceImpl(bundle,
- this.sharedHttpService,
- this.context,
- this.contextAttributeListenerManager,
- this.sharedContextAttributes,
- this.requestListenerManager,
- this.requestAttributeListenerManager);
+ final ServletContext servletContext = this.context;
+ if ( servletContext != null ) {
+ return new PerBundleHttpServiceImpl(bundle,
+ this.sharedHttpService,
+ this.context,
+ this.contextAttributeListenerManager,
+ this.sharedContextAttributes,
+ this.requestListenerManager,
+ this.requestAttributeListenerManager);
+ }
+ return null;
}
@Override