Fix a couple of bugs in substring matching and null handling when
matching collections. (FELIX-3207)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1199603 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java b/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
index 9d5fd48..62813ac 100644
--- a/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
+++ b/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
@@ -366,10 +366,15 @@
         return false;
     }
 
-    private static final Class[] STRING_CLASS = new Class[] { String.class };
+    private static final Class<?>[] STRING_CLASS = new Class[] { String.class };
 
     private static boolean compare(Object lhs, Object rhsUnknown, int op)
     {
+        if (lhs == null)
+        {
+            return false;
+        }
+        
         // If this is a PRESENT operation, then just return true immediately
         // since we wouldn't be here if the attribute wasn't present.
         if (op == SimpleFilter.PRESENT)
diff --git a/framework/src/main/java/org/apache/felix/framework/capabilityset/SimpleFilter.java b/framework/src/main/java/org/apache/felix/framework/capabilityset/SimpleFilter.java
index cc4e0fe..93591b5 100644
--- a/framework/src/main/java/org/apache/felix/framework/capabilityset/SimpleFilter.java
+++ b/framework/src/main/java/org/apache/felix/framework/capabilityset/SimpleFilter.java
@@ -502,9 +502,9 @@
 
             // If this is the last piece, then make sure the
             // string ends with it.
-            if (i == len - 1)
+            if (i == (len - 1))
             {
-                if (s.endsWith(piece))
+                if (s.endsWith(piece) && (s.length() >= (index + piece.length())))
                 {
                     result = true;
                 }
diff --git a/framework/src/test/java/org/apache/felix/framework/capabilityset/SimpleFilterTest.java b/framework/src/test/java/org/apache/felix/framework/capabilityset/SimpleFilterTest.java
index d7e85a6..cf82a1d 100644
--- a/framework/src/test/java/org/apache/felix/framework/capabilityset/SimpleFilterTest.java
+++ b/framework/src/test/java/org/apache/felix/framework/capabilityset/SimpleFilterTest.java
@@ -73,5 +73,11 @@
 
         pieces = SimpleFilter.parseSubstring("*foo(*bar*");
         assertTrue("Should match!", SimpleFilter.compareSubstring(pieces, "foo()bar"));
+
+        pieces = SimpleFilter.parseSubstring("*foo*bar*bar");
+        assertFalse("Should not match!", SimpleFilter.compareSubstring(pieces, "foobar"));
+
+        pieces = SimpleFilter.parseSubstring("aaaa*aaaa");
+        assertFalse("Should not match!", SimpleFilter.compareSubstring(pieces, "aaaaaaa"));
     }
 }