Fix regression with covariant property return types
Prior to this change, the Property class introduced in 3.1 M2 validated read/write property method pairs based on whether their parameter/return types were equal to one another. This precluded the valid possibility of read method that returns a subtype of the write method's parameter type, and represented a regression against 3.1 M1 and earlier versions. The implementation now uses isAssignableFrom rather than a straight equals check against the types. Issue: SPR-8432
This commit is contained in:
@@ -133,8 +133,8 @@ public final class Property {
|
||||
if (read == null && write == null) {
|
||||
throw new IllegalStateException("Property is neither readable nor writeable");
|
||||
}
|
||||
if (read != null && write != null && !read.getParameterType().equals(write.getParameterType())) {
|
||||
throw new IllegalStateException("Read and write parameter types are not the same");
|
||||
if (read != null && write != null && !write.getParameterType().isAssignableFrom(read.getParameterType())) {
|
||||
throw new IllegalStateException("Write parameter is not assignable from read parameter");
|
||||
}
|
||||
return read != null ? read : write;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user