FELIX-3823 Make sure the default FilePersistenceManager is properly unregistered by the bundle itself

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1421783 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java b/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
index d9dc3ab..54d78ee 100644
--- a/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
+++ b/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
@@ -127,6 +127,9 @@
     // the BundleContext of the Configuration Admin Service bundle
     BundleContext bundleContext;
 
+    // the service registration of the default file persistence manager
+    private volatile ServiceRegistration filepmRegistration;
+
     // the service registration of the configuration admin
     private volatile ServiceRegistration configurationAdminRegistration;
 
@@ -245,7 +248,7 @@
             props.put( Constants.SERVICE_DESCRIPTION, "Platform Filesystem Persistence Manager" );
             props.put( Constants.SERVICE_VENDOR, "Apache Software Foundation" );
             props.put( Constants.SERVICE_RANKING, new Integer( Integer.MIN_VALUE ) );
-            bundleContext.registerService( PersistenceManager.class.getName(), fpm, props );
+            filepmRegistration = bundleContext.registerService( PersistenceManager.class.getName(), fpm, props );
 
             // setup dynamic configuration bindings
             dynamicBindings = new DynamicBindings( bundleContext, fpm );
@@ -316,10 +319,11 @@
         // clearing the field before actually unregistering the service
         // prevents IllegalStateException in getServiceReference() if
         // the field is not null but the service already unregistered
-        if (configurationAdminRegistration != null) {
-            ServiceRegistration reg = configurationAdminRegistration;
-            configurationAdminRegistration = null;
-            reg.unregister();
+        final ServiceRegistration caReg = configurationAdminRegistration;
+        configurationAdminRegistration = null;
+        if ( caReg != null )
+        {
+            caReg.unregister();
         }
 
         // consider inactive after unregistering such that during
@@ -329,6 +333,14 @@
         // don't care for PersistenceManagers any more
         persistenceManagerTracker.close();
 
+        // shutdown the file persistence manager
+        final ServiceRegistration filePmReg = filepmRegistration;
+        filepmRegistration = null;
+        if ( filePmReg != null )
+        {
+            filePmReg.unregister();
+        }
+
         // stop listening for events
         bundleContext.removeBundleListener( this );