commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shen liang (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CONFIGURATION-566) BeanHelper.createBean() can't support Map<> bean property loading from file
Date Sun, 16 Feb 2014 01:36:20 GMT

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

Shen liang commented on CONFIGURATION-566:
------------------------------------------

How to repeat the issue:

Define a bean as a child class of HashMap
{code:java}
public class Setting extends HashMap<String, Setting.Configuration>
{
     public static class Configuration()
     {
            public String item;
     }    
} 
{code}

The above bean will cause the error when try to load it from the XML file.

FIX: 
remark the additional check in the BeanHelper::initProperty() like the following
{code:java}
 private static void initProperty(Object bean, String propName, Object value)
            throws ConfigurationRuntimeException
    {

        //It is redundant and case the Map bean can't be set properly
//        if (!PropertyUtils.isWriteable(bean, propName))
//        {
//            throw new ConfigurationRuntimeException("Property " + propName
//                                                            + " cannot be set on " + bean.getClass().getName());
//        }

        try
        {
            BeanUtils.setProperty(bean, propName, value);
        }
        catch (IllegalAccessException iaex)
        {
            throw new ConfigurationRuntimeException(iaex);
        }
        catch (InvocationTargetException itex)
        {
            throw new ConfigurationRuntimeException(itex);
        }
    }
{code}

> BeanHelper.createBean() can't support Map<> bean property loading from file
> ---------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-566
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-566
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: Type conversion
>    Affects Versions: 1.10
>            Reporter: Shen liang
>
> The issue is BeanUtils.setProperty() can support the java Map bean to set the (key, value)
entry. But the BeahHelper.initProperty() add 1 more PropertyUtils.isWriteable() check. While
this PropertyUtils.isWriteable() doesn't support java Map bean. 
> The check "PropertyUtils.isWriteable()" is quite redundant and unnecessary.
>   
> Is it better to remove the check "PropertyUtils.isWriteable()" since the BeanUtils.setProperty()
has various ways to set the properties?
> {noformat}
> BeanHelper.createBean() 
>  -> DefaultBeanFactory.createBean()
>       -> DefaultBeanFactory.initBeanInstance()
>            -> BeanHelper.initBean()
>                 ->BeahHelper.initProperty()
>                    {
>                         if (!PropertyUtils.isWriteable(bean, propName))
>                         ...
>                         BeanUtils.setProperty(bean, propName, value);
>                    }
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Mime
View raw message