Bug 461102 - NPE in OperationFactory.listInstalledElements

Change-Id: I3bfff65bdcd579398434c1a19c1642be5d2f34c0
Signed-off-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
diff --git a/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/p2/operations/OperationFactory.java b/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/p2/operations/OperationFactory.java
index e5769a5..c016de2 100644
--- a/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/p2/operations/OperationFactory.java
+++ b/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/p2/operations/OperationFactory.java
@@ -123,14 +123,18 @@
 	}
 
 	/**
-	 * Return the {@link IInstallableUnit} that are installed in the running instance of eclipse.
+	 * Returns the {@link IInstallableUnit}s that are installed in the running instance of Eclipse.
+	 *
 	 * @param rootsOnly set to true to return only the elements that have been explicitly installed (aka roots).
 	 * @param monitor the progress monitor
-	 * @return the installable units installed
+	 * @return the installable units installed, or an empty result if the installation profile of the running system
+	 *     cannot be accessed
 	 */
 	public IQueryResult<IInstallableUnit> listInstalledElements(boolean rootsOnly, IProgressMonitor monitor) {
 		IProfileRegistry registry = (IProfileRegistry) getAgent().getService(IProfileRegistry.SERVICE_NAME);
 		IProfile profile = registry.getProfile(IProfileRegistry.SELF);
+		if (profile == null)
+			return new CollectionResult<IInstallableUnit>(null);
 		if (rootsOnly)
 			return profile.query(new UserVisibleRootQuery(), monitor);
 		return profile.query(QueryUtil.ALL_UNITS, monitor);