commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Benedikt Ritter (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (BEANUTILS-393) BeanUtilsBean sets a wrong type to value when mapped key is set
Date Sun, 24 Feb 2013 13:08:13 GMT

    [ https://issues.apache.org/jira/browse/BEANUTILS-393?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13585362#comment-13585362
] 

Benedikt Ritter commented on BEANUTILS-393:
-------------------------------------------

Hi Krolikowski,

can you please provide a JUnit test that shows erroneous behavior and the patch you propose
as SVN patch file?

TIA!
Benedikt
                
> 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.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message