Overview
After fixing the bugs related to #36019, I noticed that PropertyDescriptorUtils still does not reliably resolve the correct write method if an overloaded candidate write method has a parameter type that is a subtype of another candidate write method whose parameter is an exact match for the resolved read method's return type. Whereas, we should always select an exact match for the write method whenever possible.
Although we consider this a bug, we currently only plan to fix this in 7.0.x, thereby foregoing a backport to 6.2.x that could result in regressions in the 6.2.x line which we would like to avoid.
Example
|
@Test |
|
void resolvePropertiesWithUnresolvedGenericsInSubclassWithOverloadedSetter() { |
|
var pdMap = resolver.resolve(PersonWithOverloadedSetter.class); |
|
|
|
Class<?> writeType = Number.class; |
|
if (resolver instanceof BasicPropertiesResolver) { |
|
// TODO: PropertyDescriptorUtils currently incorrectly resolves setId(Integer) |
|
// as the write method instead of setId(Number) (where Number is the |
|
// unresolved generic for Long). |
|
writeType = Integer.class; |
|
} |
|
|
|
assertReadAndWriteMethodsForClassAndId(pdMap, Number.class, writeType); |
|
} |
Related Issues
Overview
After fixing the bugs related to #36019, I noticed that
PropertyDescriptorUtilsstill does not reliably resolve the correct write method if an overloaded candidate write method has a parameter type that is a subtype of another candidate write method whose parameter is an exact match for the resolved read method's return type. Whereas, we should always select an exact match for the write method whenever possible.Although we consider this a bug, we currently only plan to fix this in 7.0.x, thereby foregoing a backport to 6.2.x that could result in regressions in the 6.2.x line which we would like to avoid.
Example
spring-framework/spring-beans/src/test/java/org/springframework/beans/PropertyDescriptorUtilsPropertyResolutionTests.java
Lines 386 to 399 in 992ae2e
Related Issues
PropertyDescriptorUtilsdoes not reliably resolve read/write methods in type hierarchies with generics #36019