Sergey Chernov created BEANUTILS-541:
----------------------------------------
Summary: FluentPropertyBeanIntrospector caches corrupted
writeMethod (two subclasses)
Key: BEANUTILS-541
URL: https://issues.apache.org/jira/browse/BEANUTILS-541
Project: Commons BeanUtils
Issue Type: Bug
Components: Bean / Property Utils
Affects Versions: 1.9.3, 1.9.2, 1.9.1, 1.9.0
Reporter: Sergey Chernov
There is an issue in {{FluentPropertyBeanIntrospector}}, it caches wrong
writeMethod in the static cache of {{java.beans.Introspector when base class
has at least two subclasses}}. Simple snippet to reproduce:
{code:java}
import org.apache.commons.beanutils.FluentPropertyBeanIntrospector;
import org.apache.commons.beanutils.PropertyUtilsBean;
public class BeanUtilsTest {
public static void main(String[] args) throws Exception {
PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean();
propertyUtilsBean.addBeanIntrospector(new
FluentPropertyBeanIntrospector());
// invert if condition and it will succeed
if (true) {
// fails
SubTypeA subTypeA = new SubTypeA();
//subTypeA.setField("name");
propertyUtilsBean.setProperty(subTypeA, "field", "name");
SubTypeB subTypeB = new SubTypeB();
//subTypeB.setField("name");
propertyUtilsBean.setProperty(subTypeB, "field", "name");
} else {
// the same as above, but reverse order - success
SubTypeB subTypeB = new SubTypeB();
//subTypeB.setField("name");
propertyUtilsBean.setProperty(subTypeB, "field", "name");
SubTypeA subTypeA = new SubTypeA();
//subTypeA.setField("name");
propertyUtilsBean.setProperty(subTypeA, "field", "name");
}
}
public static class BaseType {
private String field;
public BaseType setField(String objectName) {
this.field = objectName;
return this;
}
public String getField() {
return field;
}
}
public static class SubTypeA extends BaseType {
@Override
public SubTypeA setField(String field) {
super.setField(field);
return this;
}
}
public static class SubTypeB extends BaseType {
}
}
{code}
It is critical, because wrong information is stored globally unless explicit
{{Introspector.flushCaches}} ({{Introspector.flushFromCaches}}) is called.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)