Bug 475760 - Bundles with a header "Bundle-NativeCode = *" lead to an invalid filter being generated "(|)"
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 2981cdb..b420fe2 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
@@ -1955,6 +1955,16 @@
 		Assert.assertEquals("Wrong bundle provider", a.getCurrentRevision(), bundleWires.get(0).getProvider());
 	}
 
+	@Test
+	public void testBadNativeCode() throws IOException {
+		try {
+			OSGiManifestBuilderFactory.createBuilder(getManifest("bad.native.code.MF"));
+		} catch (BundleException e) {
+			Assert.assertEquals("Wrong exception type.", BundleException.MANIFEST_ERROR, e.getType());
+		}
+
+	}
+
 	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.tests/test_files/containerTests/bad.native.code.MF b/bundles/org.eclipse.osgi.tests/test_files/containerTests/bad.native.code.MF
new file mode 100755
index 0000000..951f4d5
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/test_files/containerTests/bad.native.code.MF
@@ -0,0 +1,5 @@
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: bad.native.code
+Bundle-Version: 1.0.0
+Bundle-NativeCode: *
+
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/builders/OSGiManifestBuilderFactory.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/builders/OSGiManifestBuilderFactory.java
index 846681b..e1f1352 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/builders/OSGiManifestBuilderFactory.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/builders/OSGiManifestBuilderFactory.java
@@ -957,10 +957,16 @@
 		}
 		Collections.sort(nativeClauses);
 
-		Map<String, Object> attributes = new HashMap<String, Object>(2);
 		int numNativePaths = nativeClauses.size();
+		if (numNativePaths == 0) {
+			String msg = "No native code clauses found in the value of " + Constants.BUNDLE_NATIVECODE + ": " + manifest.get(Constants.BUNDLE_NATIVECODE); //$NON-NLS-1$//$NON-NLS-2$
+			throw new BundleException(msg, BundleException.MANIFEST_ERROR);
+		}
 		StringBuilder allNativeFilters = new StringBuilder();
-		allNativeFilters.append("(|"); //$NON-NLS-1$
+		if (numNativePaths > 1) {
+			allNativeFilters.append("(|"); //$NON-NLS-1$
+		}
+		Map<String, Object> attributes = new HashMap<String, Object>(2);
 		for (int i = 0; i < numNativePaths; i++) {
 			NativeClause nativeClause = nativeClauses.get(i);
 			if (numNativePaths == 1) {
@@ -970,7 +976,9 @@
 			}
 			allNativeFilters.append(nativeClauses.get(i).filter);
 		}
-		allNativeFilters.append(')');
+		if (numNativePaths > 1) {
+			allNativeFilters.append(')');
+		}
 
 		Map<String, String> directives = new HashMap<String, String>(2);
 		directives.put(NativeNamespace.REQUIREMENT_FILTER_DIRECTIVE, allNativeFilters.toString());