Improved handling Bundle-Version. (FELIX-851)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@738197 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
index d532af7..90c86f3 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
@@ -965,9 +965,9 @@
                 if (id != getBundleId())
                 {
                     String sym = bundles[i].getSymbolicName();
-                    Version ver = Version.parseVersion((String) ((BundleImpl) bundles[i])
-                        .getCurrentModule().getHeaders().get(Constants.BUNDLE_VERSION));
-                    if (symName.equals(sym) && bundleVersion.equals(ver))
+                    Version ver = ((ModuleImpl)
+                        ((BundleImpl) bundles[i]).getCurrentModule()).getVersion();
+                    if ((symName != null) && (sym != null) && symName.equals(sym) && bundleVersion.equals(ver))
                     {
                         throw new BundleException("Bundle symbolic name and version are not unique: " + sym + ':' + ver);
                     }
diff --git a/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java b/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
index a22a0f4..9b789a1 100644
--- a/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
+++ b/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
@@ -63,14 +63,34 @@
         Map dupeMap = new HashMap();
 
         //
+        // Parse bundle version.
+        //
+
+        m_bundleVersion = Version.emptyVersion;
+        if (headerMap.get(Constants.BUNDLE_VERSION) != null)
+        {
+            try
+            {
+                m_bundleVersion = Version.parseVersion((String) headerMap.get(Constants.BUNDLE_VERSION));
+            }
+            catch (RuntimeException ex)
+            {
+                // R4 bundle versions must parse, R3 bundle version may not.
+                if (manifestVersion.equals("2"))
+                {
+                    throw ex;
+                }
+                m_bundleVersion = Version.emptyVersion;
+            }
+        }
+
+        //
         // Parse bundle symbolic name.
         //
 
         ICapability moduleCap = parseBundleSymbolicName(m_headerMap);
         if (moduleCap != null)
         {
-            m_bundleVersion = (Version)
-                moduleCap.getProperties().get(Constants.BUNDLE_VERSION_ATTRIBUTE);
             m_bundleSymbolicName = (String)
                 moduleCap.getProperties().get(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE);
 
@@ -811,7 +831,7 @@
             }
 
             // Get bundle version.
-            Version bundleVersion = null;
+            Version bundleVersion = Version.emptyVersion;
             if (headerMap.get(Constants.BUNDLE_VERSION) != null)
             {
                 try