aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java
diff options
context:
space:
mode:
authorPontus Boström <pontus@vaadin.com>2016-07-26 12:26:54 +0300
committerVaadin Code Review <review@vaadin.com>2016-08-01 07:53:34 +0000
commit6688e6617275120bfc39cd31c464fd9b2a594a79 (patch)
tree0d641b719161bb79386223e479ce26f0f93dd5f7 /server/src/main/java
parent77ad774461cb7a609878515172605787631a1b15 (diff)
downloadvaadin-framework-6688e6617275120bfc39cd31c464fd9b2a594a79.tar.gz
vaadin-framework-6688e6617275120bfc39cd31c464fd9b2a594a79.zip
Fixed the compare filter to handle subclasses (#17169)
Earlier the comparision worked only if the item value was a subclass of the value in comparator, but not in the other way around. Now the compairision works if the one is a subclass of the other and both implements Comparable. Change-Id: I1bcbba94f1263915f838e948ed9d8b68a14aefd0
Diffstat (limited to 'server/src/main/java')
-rw-r--r--server/src/main/java/com/vaadin/data/util/filter/Compare.java12
1 files changed, 9 insertions, 3 deletions
diff --git a/server/src/main/java/com/vaadin/data/util/filter/Compare.java b/server/src/main/java/com/vaadin/data/util/filter/Compare.java
index 1fcbe85580..60523f2d42 100644
--- a/server/src/main/java/com/vaadin/data/util/filter/Compare.java
+++ b/server/src/main/java/com/vaadin/data/util/filter/Compare.java
@@ -292,9 +292,15 @@ public abstract class Compare implements Filter {
return null == value1 ? 0 : -1;
} else if (null == value1) {
return 1;
- } else if (getValue() instanceof Comparable
- && value1.getClass().isAssignableFrom(getValue().getClass())) {
- return -((Comparable) getValue()).compareTo(value1);
+ } else if (getValue() instanceof Comparable) {
+ if (value1.getClass().isInstance(getValue())) {
+ return -((Comparable) getValue()).compareTo(value1);
+ } else if (getValue().getClass().isInstance(value1)) {
+ // isInstance returns true if value1 is a sub-type of
+ // getValue(), i.e. value1 must here be Comparable
+ return ((Comparable) value1).compareTo(getValue());
+ }
+
}
throw new IllegalArgumentException("Could not compare the arguments: "
+ value1 + ", " + getValue());