Description
MethodGetAndSet.setValue uses wrong source to determine which type to convert to when there's no setter, resulting in exceptions like this:
org.apache.wicket.WicketRuntimeException: Error setting field: private int PropertyResolverTest$DirectFieldSetWithDifferentTypeThanGetter.value on object: PropertyResolverTest$DirectFieldSetWithDifferentTypeThanGetter@396477d9
at org.apache.wicket.util.lang.PropertyResolver$MethodGetAndSet.setValue(PropertyResolver.java:1150)
at org.apache.wicket.util.lang.PropertyResolver$ObjectAndGetSetter.setValue(PropertyResolver.java:588)
at org.apache.wicket.util.lang.PropertyResolver.setValue(PropertyResolver.java:136)
at PropertyResolverTest.testDirectFieldSetWithDifferentTypeThanGetter(PropertyResolverTest.java:12)
Bug is located in:
converted = converter.convert(value, getMethod.getReturnType());
Instead, it should read:
converted = converter.convert(value, type);
Testcase attached.
Additional thoughts:
if (setMethod != null)
{
type = getMethod.getReturnType();
}
This is really confusing (we check setMethod presence but get type from getMethod). Luckily, this works as expected because in MethodGetAndSet.findSetter only methods with same (or superclass) type as getter are returned.