Perform null check when trying to get bundle from service reference. (FELIX-3842)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1430412 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/LocalRepositoryImpl.java b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/LocalRepositoryImpl.java
index 71b0fb9..5d52f3a 100644
--- a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/LocalRepositoryImpl.java
+++ b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/LocalRepositoryImpl.java
@@ -1,4 +1,4 @@
-/* 
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -68,7 +68,8 @@
     public void serviceChanged(ServiceEvent event)
     {
         Bundle bundle = event.getServiceReference().getBundle();
-        if (bundle.getState() == Bundle.ACTIVE && event.getType() != ServiceEvent.MODIFIED)
+        if ((bundle != null)
+            && (bundle.getState() == Bundle.ACTIVE && event.getType() != ServiceEvent.MODIFIED))
         {
             synchronized (this)
             {
@@ -81,7 +82,6 @@
 
     private void addBundle(Bundle bundle, Logger logger)
     {
-        
         /*
          * Concurrency note: This method MUST be called in a context which
          * is synchronized on this instance to prevent data structure
@@ -104,19 +104,18 @@
             m_logger.log(Logger.LOG_WARNING, ex.getMessage(), ex);
         }
     }
-    
+
     private void removeBundle(Bundle bundle, Logger logger)
     {
-        
         /*
          * Concurrency note: This method MUST be called in a context which
          * is synchronized on this instance to prevent data structure
          * corruption.
          */
-        
+
         m_localResourceList.remove(new Long(bundle.getBundleId()));
     }
-    
+
     public void dispose()
     {
         m_context.removeBundleListener(this);
@@ -150,9 +149,9 @@
         m_context.addServiceListener(this);
 
         // Generate the resource list from the set of installed bundles.
-        // Lock so we can ensure that no bundle events arrive before we 
+        // Lock so we can ensure that no bundle events arrive before we
         // are done getting our state snapshot.
-        Bundle[] bundles = null;
+        Bundle[] bundles;
         synchronized (this)
         {
             // Create a local resource object for each bundle, which will
@@ -166,5 +165,4 @@
             m_snapshotTimeStamp = System.currentTimeMillis();
         }
     }
-
-}
+}
\ No newline at end of file