Exceptions thrown by equals()/compare() should result in a false
for filter evaluation. (FELIX-2998)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1136102 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 fedc1b2..4134489 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
@@ -407,11 +407,32 @@
switch (op)
{
case SimpleFilter.EQ :
- return (((Comparable) lhs).compareTo(rhs) == 0);
+ try
+ {
+ return (((Comparable) lhs).compareTo(rhs) == 0);
+ }
+ catch (Exception ex)
+ {
+ return false;
+ }
case SimpleFilter.GTE :
- return (((Comparable) lhs).compareTo(rhs) >= 0);
+ try
+ {
+ return (((Comparable) lhs).compareTo(rhs) >= 0);
+ }
+ catch (Exception ex)
+ {
+ return false;
+ }
case SimpleFilter.LTE :
- return (((Comparable) lhs).compareTo(rhs) <= 0);
+ try
+ {
+ return (((Comparable) lhs).compareTo(rhs) <= 0);
+ }
+ catch (Exception ex)
+ {
+ return false;
+ }
case SimpleFilter.APPROX :
return compareApproximate(((Comparable) lhs), rhs);
case SimpleFilter.SUBSTRING :
@@ -478,27 +499,14 @@
// Since we cannot identify the LHS type, then we can only perform
// equality comparison.
-// TODO: COMPLIANCE - This should be changed to return false in case
-// of an exception, but the R4.2 CT has a mistake in it, so for
-// now we'll throw exceptions from equals().
-// try
-// {
-// return lhs.equals(coerceType(lhs, (String) rhsUnknown));
-// }
-// catch (Exception ex)
-// {
-// return false;
-// }
- Object rhsObj = null;
try
{
- rhsObj = coerceType(lhs, (String) rhsUnknown);
+ return lhs.equals(coerceType(lhs, (String) rhsUnknown));
}
catch (Exception ex)
{
return false;
}
- return lhs.equals(rhsObj);
}
private static boolean compareApproximate(Object lhs, Object rhs)
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 20ac13f..18e7adb 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
@@ -418,7 +418,7 @@
}
ss.setLength(0);
// if this is a leading star, then track it
- if (pieces.size() == 0)
+ if (pieces.isEmpty())
{
leftstar = true;
}