Bug 542537 - ModuleResolutionReport.getResolutionReportMessage throws
ClassCastException for namespace attribute

Change-Id: I1da7125489d495959448ea2a0d086162b6e266e6
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
Signed-off-by: Anjum Fatima <anjum.eclipse@gmail.com>
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java
index 57ef9d4..813a018 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java
@@ -3469,6 +3469,33 @@
 		}
 	}
 
+	@Test
+	public void testAliasBundleNameReport() throws BundleException, IOException {
+		DummyContainerAdaptor adaptor = createDummyAdaptor();
+		ModuleContainer container = adaptor.getContainer();
+
+		Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
+		container.resolve(Collections.singleton(systemBundle), true);
+
+		Map<String, String> b1Manifest = new HashMap<>();
+		b1Manifest.put(Constants.BUNDLE_SYMBOLICNAME, "b1");
+		b1Manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
+		b1Manifest.put(Constants.IMPORT_PACKAGE, "doesnotexist");
+		ModuleRevisionBuilder b1Builder = OSGiManifestBuilderFactory.createBuilder(b1Manifest, "alias.name", "", "");
+		container.install(systemBundle, "b1", b1Builder, null);
+
+		Map<String, String> b2Manifest = new HashMap<>();
+		b2Manifest.put(Constants.BUNDLE_SYMBOLICNAME, "b2");
+		b2Manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
+		b2Manifest.put(Constants.REQUIRE_BUNDLE, "b1");
+		ModuleRevisionBuilder b2Builder = OSGiManifestBuilderFactory.createBuilder(b2Manifest);
+		Module b2 = container.install(systemBundle, "b2", b2Builder, null);
+
+		ResolutionReport report = container.resolve(Collections.singleton(b2), true);
+		String message = report.getResolutionReportMessage(b2.getCurrentRevision());
+		assertTrue("Wrong error message: " + message, message.contains("b1") && message.contains("alias.name"));
+	}
+
 	private static void assertWires(List<ModuleWire> required, List<ModuleWire>... provided) {
 		for (ModuleWire requiredWire : required) {
 			for (List<ModuleWire> providedList : provided) {
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolutionReport.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolutionReport.java
index 08cc43c..2e02139 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolutionReport.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolutionReport.java
@@ -169,7 +169,7 @@
 	private static String createOSGiCapability(Capability cap) {
 		Map<String, Object> attributes = new HashMap<>(cap.getAttributes());
 		Map<String, String> directives = cap.getDirectives();
-		String name = (String) attributes.remove(cap.getNamespace());
+		String name = String.valueOf(attributes.remove(cap.getNamespace()));
 		return name + ModuleRevision.toString(attributes, false, true) + ModuleRevision.toString(directives, true, true);
 	}