Bug 468774 - NPE in org.eclipse.equinox.region when
installing/uninstalling bundles
diff --git a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java
index 6910603..e021466 100644
--- a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java
+++ b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java
@@ -18,6 +18,7 @@
 import javax.management.*;
 import org.eclipse.equinox.region.*;
 import org.osgi.framework.*;
+import org.osgi.framework.hooks.bundle.CollisionHook;
 import org.osgi.framework.hooks.resolver.ResolverHook;
 import org.osgi.framework.hooks.resolver.ResolverHookFactory;
 import org.osgi.framework.wiring.*;
@@ -530,6 +531,33 @@
 		}
 	}
 
+	public void testBundleCollisionUninstalledBundle() throws BundleException {
+		Region region1 = digraph.createRegion(getName() + 1);
+		Region region2 = digraph.createRegion(getName() + 2);
+		Region region3 = digraph.createRegion(getName() + 3);
+		// install the same bundle into the first two regions.  Should be no collision
+		bundleInstaller.installBundle(PP1, region1);
+		bundleInstaller.installBundle(PP1, region2);
+
+		ServiceRegistration<CollisionHook> collisionHookREg = getContext().registerService(CollisionHook.class, new CollisionHook() {
+			@Override
+			public void filterCollisions(int operationType, Bundle target, Collection<Bundle> collisionCandidates) {
+				for (Bundle bundle : collisionCandidates) {
+					try {
+						bundle.uninstall();
+					} catch (BundleException e) {
+						e.printStackTrace();
+					}
+				}
+			}
+		}, new Hashtable<String, Object>(Collections.singletonMap(Constants.SERVICE_RANKING, Integer.MAX_VALUE)));
+		try {
+			bundleInstaller.installBundle(PP1, region3);
+		} finally {
+			collisionHookREg.unregister();
+		}
+	}
+
 	public void testBundleCollisionConnectedRegions() throws BundleException, InvalidSyntaxException {
 		// get the system region
 		Region systemRegion = digraph.getRegion(0);
diff --git a/bundles/org.eclipse.equinox.region/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.region/META-INF/MANIFEST.MF
index 65ffb67..c1cbf46 100644
--- a/bundles/org.eclipse.equinox.region/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.region/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %Bundle-Name
 Bundle-SymbolicName: org.eclipse.equinox.region
-Bundle-Version: 1.2.100.qualifier
+Bundle-Version: 1.2.200.qualifier
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Fragment-Host: system.bundle
 ExtensionBundle-Activator: org.eclipse.equinox.internal.region.RegionManager
diff --git a/bundles/org.eclipse.equinox.region/pom.xml b/bundles/org.eclipse.equinox.region/pom.xml
index c29f4c0..48c6b61 100644
--- a/bundles/org.eclipse.equinox.region/pom.xml
+++ b/bundles/org.eclipse.equinox.region/pom.xml
@@ -19,6 +19,6 @@
   </parent>
   <groupId>org.eclipse.equinox</groupId>
   <artifactId>org.eclipse.equinox.region</artifactId>
-  <version>1.2.100-SNAPSHOT</version>
+  <version>1.2.200-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 </project>
diff --git a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/hook/RegionBundleCollisionHook.java b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/hook/RegionBundleCollisionHook.java
index 1ab76a9..860f894 100644
--- a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/hook/RegionBundleCollisionHook.java
+++ b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/hook/RegionBundleCollisionHook.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011 VMware Inc.
+ * Copyright (c) 2011, 2015 VMware Inc.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -68,6 +68,10 @@
 			// does not collide from the perspective of the collision candidate regions
 			for (Bundle collisionCandidate : collisionCandidates) {
 				Region candidateRegion = regionDigraph.getRegion(collisionCandidate);
+				if (candidateRegion == null) {
+					// we assume the candidate has been uninstalled; do not consider the candidate as a collision
+					continue;
+				}
 				// we know the collision candidates all have the BSN/Version that collide.
 				// we use the collision candidate and pretend it is part of the target region
 				// to see if we can see it from the candidateRegion