[ https://issues.apache.org/jira/browse/BEANUTILS-393?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Benedikt Ritter updated BEANUTILS-393: -------------------------------------- Fix Version/s: 1.8.4 > BeanUtilsBean sets a wrong type to value when mapped key is set > --------------------------------------------------------------- > > Key: BEANUTILS-393 > URL: https://issues.apache.org/jira/browse/BEANUTILS-393 > Project: Commons BeanUtils > Issue Type: Bug > Components: Bean / Property Utils > Affects Versions: 1.8.3 > Environment: any > Reporter: Krolikowski > Fix For: 1.8.4 > > > In my opinion line no 968 in org.apache.commons.beanutils.BeanUtilsBean sets > the wrong value to "type" variable. > Look: > {code:title=BeanUtilsBean.java} > if (descriptor instanceof MappedPropertyDescriptor) { > if (((MappedPropertyDescriptor) > descriptor).getMappedWriteMethod() == null) { > if (log.isDebugEnabled()) { > log.debug("Skipping read-only property"); > } > return; // Read-only, skip this property setter > } > type = ((MappedPropertyDescriptor) descriptor). > getMappedPropertyType(); > } else if (index >= 0 && descriptor instanceof > IndexedPropertyDescriptor) { > if (((IndexedPropertyDescriptor) > descriptor).getIndexedWriteMethod() == null) { > if (log.isDebugEnabled()) { > log.debug("Skipping read-only property"); > } > return; // Read-only, skip this property setter > } > type = ((IndexedPropertyDescriptor) descriptor). > getIndexedPropertyType(); > } else if (key != null) { > if (descriptor.getReadMethod() == null) { > if (log.isDebugEnabled()) { > log.debug("Skipping read-only property"); > } > return; // Read-only, skip this property setter > } > type = (value == null) ? Object.class : value.getClass(); // > here is the bug, imho!!! > } else { > if (descriptor.getWriteMethod() == null) { > if (log.isDebugEnabled()) { > log.debug("Skipping read-only property"); > } > return; // Read-only, skip this property setter > } > type = descriptor.getPropertyType(); > } > {code} > For example: Variable "value" can be an instance of String[]. It will have > this value if there is a property "test" type of Hashmap<String,String> in > bean and a property "test(123)" will come from the form. Variable "value" > will have a value String[] {"123"}. > The variable "type" should get in this case a value of String.class, not > String[].class (not an array), what happens in this line: > {code} > type = (value == null) ? Object.class : value.getClass(); > {code} > This bug and the of populating data gives an exception: > java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to > java.lang.String, > when accessing test.get("123"). -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira