[3.21] 501993: fix NullPointerException in DefaultSupportHandler.getDescription

Change-Id: I17bbf252f1980c4631f02d8f1420cc9207f57a97
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=501993
Signed-off-by: Jaxsun McCarthy Huggan <jaxsun.mccarthy@tasktop.com>
diff --git a/org.eclipse.mylyn.tasks.bugs/src/org/eclipse/mylyn/internal/tasks/bugs/DefaultSupportHandler.java b/org.eclipse.mylyn.tasks.bugs/src/org/eclipse/mylyn/internal/tasks/bugs/DefaultSupportHandler.java
index 4ae9988..c186096 100644
--- a/org.eclipse.mylyn.tasks.bugs/src/org/eclipse/mylyn/internal/tasks/bugs/DefaultSupportHandler.java
+++ b/org.eclipse.mylyn.tasks.bugs/src/org/eclipse/mylyn/internal/tasks/bugs/DefaultSupportHandler.java
@@ -80,10 +80,8 @@
 			}
 		}
 		if (response.getProduct() != null) {
-			IBundleGroup bundleGroup = ((SupportProduct) response.getProduct()).getVersioningBundleGroup();
-			if (bundleGroup == null) {
-				bundleGroup = ((SupportProduct) response.getProduct()).getBundleGroup();
-			}
+			SupportProduct supportProduct = (SupportProduct) response.getProduct();
+			IBundleGroup bundleGroup = getBundleGroup(supportProduct);
 			if (bundleGroup != null) {
 				TaskAttribute attribute = taskData.getRoot().getMappedAttribute(TaskAttribute.VERSION);
 				if (attribute != null) {
@@ -104,6 +102,14 @@
 		}
 	}
 
+	private IBundleGroup getBundleGroup(SupportProduct supportProduct) {
+		IBundleGroup bundleGroup = supportProduct.getVersioningBundleGroup();
+		if (bundleGroup == null) {
+			bundleGroup = supportProduct.getBundleGroup();
+		}
+		return bundleGroup;
+	}
+
 	private String getBestMatch(String version, Map<String, String> options) {
 		String match = ""; //$NON-NLS-1$
 		for (String option : options.values()) {
@@ -156,45 +162,19 @@
 	public String getDescription(IStatus status) {
 		if (status instanceof ProductStatus) {
 			SupportProduct product = (SupportProduct) ((ProductStatus) status).getProduct();
-			if (product.getBundleGroup() != null) {
+			IBundleGroup bundleGroup = product.getBundleGroup();
+			if (bundleGroup != null) {
 				StringBuilder sb = new StringBuilder();
 				sb.append("\n\n\n"); //$NON-NLS-1$
 				sb.append(Messages.DefaultSupportHandler_Configuration_Details);
 				appendProductInformation(sb);
-				sb.append("\n"); //$NON-NLS-1$
 				sb.append(Messages.DefaultSupportHandler_Installed_Features);
-				sb.append("\n"); //$NON-NLS-1$
-				for (IBundleGroup bundleGroup : new IBundleGroup[] { product.getBundleGroup() }) {
-					sb.append(" "); //$NON-NLS-1$
-					sb.append(bundleGroup.getIdentifier());
-					sb.append(" "); //$NON-NLS-1$
-					sb.append(bundleGroup.getVersion());
-					sb.append("\n"); //$NON-NLS-1$
-
-//					Bundle[] bundles = bundleGroup.getBundles();
-//					if (bundles != null) {
-//						for (Bundle bundle : bundles) {
-//							sb.append("  "); //$NON-NLS-1$
-//							sb.append(bundle.getSymbolicName());
-//							String version = (String) bundle.getHeaders().get(
-//									Messages.DefaultTaskContributor_Bundle_Version);
-//							if (version != null) {
-//								sb.append(" "); //$NON-NLS-1$
-//								sb.append(version);
-//							}
-//							sb.append("\n"); //$NON-NLS-1$
-//						}
-//					}
+				appendBundleGroup(bundleGroup, sb);
+				IBundleGroup versioningBundleGroup = product.getVersioningBundleGroup();
+				if (versioningBundleGroup != null) {
+					sb.append(Messages.DefaultSupportHandler_VersioningPlugin);
+					appendBundleGroup(versioningBundleGroup, sb);
 				}
-				sb.append(Messages.DefaultSupportHandler_VersioningPlugin);
-				sb.append("\n"); //$NON-NLS-1$
-				IBundleGroup bundleGroup = product.getVersioningBundleGroup();
-				sb.append(" "); //$NON-NLS-1$
-				sb.append(bundleGroup.getIdentifier());
-				sb.append(" "); //$NON-NLS-1$
-				sb.append(bundleGroup.getVersion());
-				sb.append("\n"); //$NON-NLS-1$
-
 				return sb.toString();
 			}
 		} else if (status instanceof ErrorLogStatus) {
@@ -222,6 +202,15 @@
 		return null;
 	}
 
+	private void appendBundleGroup(IBundleGroup bundleGroup, StringBuilder sb) {
+		sb.append("\n"); //$NON-NLS-1$
+		sb.append(" "); //$NON-NLS-1$
+		sb.append(bundleGroup.getIdentifier());
+		sb.append(" "); //$NON-NLS-1$
+		sb.append(bundleGroup.getVersion());
+		sb.append("\n"); //$NON-NLS-1$
+	}
+
 	private void appendStatus(IStatus status, StringBuilder sb, boolean includeSessionData) {
 		Date date = (status instanceof ErrorLogStatus) ? ((ErrorLogStatus) status).getDate() : null;
 		appendErrorDetails(sb, status, date);