Author: davidb
Date: Wed Jul 15 07:44:28 2015
New Revision: 1691137

URL: http://svn.apache.org/r1691137
Log:
FELIX-4960 NPE in BundleRevisionImpl.getResourcesLocal()

The NPE is fixed. Also added a unit test.

Added:
    
felix/trunk/framework/src/test/java/org/apache/felix/framework/BundleRevisionImplTest.java
Modified:
    
felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java

Modified: 
felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java?rev=1691137&r1=1691136&r2=1691137&view=diff
==============================================================================
--- 
felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
 (original)
+++ 
felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
 Wed Jul 15 07:44:28 2015
@@ -202,7 +202,7 @@ public class BundleRevisionImpl implemen
 
     static List<Capability> asCapabilityList(List reqs)
     {
-        return (List<Capability>) reqs;
+        return reqs;
     }
 
     public List<BundleCapability> getDeclaredCapabilities(String namespace)
@@ -229,7 +229,7 @@ public class BundleRevisionImpl implemen
 
     static List<Requirement> asRequirementList(List reqs)
     {
-        return (List<Requirement>) reqs;
+        return reqs;
     }
 
     public List<BundleRequirement> getDeclaredRequirements(String namespace)
@@ -517,6 +517,9 @@ public class BundleRevisionImpl implemen
         // each bundle class path entry...this isn't very
         // clean or meaningful, but the Spring guys want it.
         final List<Content> contentPath = getContentPath();
+        if (contentPath == null)
+            return Collections.emptyEnumeration();
+
         if (name.equals("/"))
         {
             for (int i = 0; i < contentPath.size(); i++)

Added: 
felix/trunk/framework/src/test/java/org/apache/felix/framework/BundleRevisionImplTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/framework/src/test/java/org/apache/felix/framework/BundleRevisionImplTest.java?rev=1691137&view=auto
==============================================================================
--- 
felix/trunk/framework/src/test/java/org/apache/felix/framework/BundleRevisionImplTest.java
 (added)
+++ 
felix/trunk/framework/src/test/java/org/apache/felix/framework/BundleRevisionImplTest.java
 Wed Jul 15 07:44:28 2015
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.framework;
+
+import java.util.Enumeration;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.felix.framework.cache.Content;
+
+public class BundleRevisionImplTest extends TestCase
+{
+    public void testGetResourcesLocalNullContentPath()
+    {
+        BundleRevisionImpl bri = new BundleRevisionImpl(null, null) {
+            @Override
+            synchronized List<Content> getContentPath()
+            {
+                return null;
+            }
+        };
+        Enumeration<?> en = bri.getResourcesLocal("foo");
+        assertFalse(en.hasMoreElements());
+    }
+}


Reply via email to