commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Krolikowski (JIRA)" <j...@apache.org>
Subject [jira] [Created] (BEANUTILS-393) BeanUtilsBean sets a wrong type to value when mapped key is set
Date Thu, 05 May 2011 20:31:03 GMT
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

Mime
View raw message