MethodProperty returns TimeStamp class instead of Date

I don’t yet have the exact line where it happens, but the Vaadin com.vaadin.data.util.MethodProperty will return a java.sql.TimeStamp object whenever you get a property for a java.util.Date field.

This is mostly unnoticeable, because Timestamp extends Date, so essentially everywhere you need your Date, you have it.

However, in the Vaadin Filter API (which is how you would filter containers) we have the com.vaadin.data.util.filter.Compare class, which applies a filter to a container. This class applies the filter via this method

protected int compareValue(Object value1) {
if (null == value) {
return null == value1 ? 0 : -1;
} else if (null == value1) {
return 1;
} else if (getValue() instanceof Comparable
&& [color=#FF0000]
[b]
value1.getClass().isAssignableFrom(getValue().getClass())
[/b]
[/color]) {
return -((Comparable) getValue()).compareTo(value1);
}
throw new IllegalArgumentException("Could not compare the arguments: "
+ value1 + ", " + getValue());
}

The highlighted line ensures that the class of the [b]
bean value
/b is assignable from the class of the [b]
filter value
/b. Which it is not.

The issue here is that one would think you could filter a Date property with a Date
value
. However because you cannot assign the Date filter value to the class of Timestamp (which is not actually the class of the field) the filter fails at this point and throws the exception.

My gut instinct is that this is a bug? Has anyone run into this?

Because these are framework classes the only easy option I can come up with is it to temporarily re-implement the Compare class and alter that line. The usages of Compare are much easier to replace than the usages of MethodPropery class, which I believe is what does the Date → Timestamp conversion. Has anyone run into this?