[
https://issues.apache.org/jira/browse/BEANUTILS-393?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13061209#comment-13061209
]
Tiago commented on BEANUTILS-393:
---------------------------------
Hi Krolikowski !!
I got the same problem here. I think its a bug in the code.
Maybe the right way must be change the line 968 :
-=-=-=-=-=-= [ from :
type = (value == null) ? Object.class : value.getClass();
-=-=-=-=-=-= [ to :
type = descriptor.getPropertyType();
To fix my problem i downgraded from 1.8.3 to 1.7.0 :(.. but i lost all new
features and bug fixeds from the new version. Other think u could do, is create
a new version of BeanUtilsBean and repack the code. :S
If u find the better solution, please let me know.
Thanks
> 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
>
> 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.
For more information on JIRA, see: http://www.atlassian.com/software/jira