commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Boland" <bola...@attbi.com>
Subject RE: PropertyUtils.getPropertyDescriptor() bug?
Date Wed, 08 May 2002 13:20:34 GMT
Answering my own question after looking at it a bit more.

I think it appears that the result should not be put into the cache but
into the Map of mappedDescriptors that was retrieved a few statements
earlier. I assume the mappedDescriptorsCache is a Map of Maps
(key=bean.getClass(), value=Map). If the mappedDescriptors == null,
should a new FastHashMap be assigned to the  mappedDescriptors variable
and also added to the cache? Maybe this should only happen if a result
is not found and a new one needs to be created.

Was...
        PropertyDescriptor result = null;
        FastHashMap mappedDescriptors =
                getMappedPropertyDescriptors(bean);
        if (mappedDescriptors != null) {
            result = (PropertyDescriptor) mappedDescriptors.get(name);
        }
        if (result == null) {
            // not found, try to create it
            try {
                result =
                        new MappedPropertyDescriptor(name,
bean.getClass());
            } catch (IntrospectionException ie) {
            }
        }
        if (result != null) {
            mappedDescriptorsCache.put(name, result);
        }
        return result;

Could be...

        PropertyDescriptor result = null;
        FastHashMap mappedDescriptors =
                getMappedPropertyDescriptors(bean);
        if (mappedDescriptors != null) {
            result = (PropertyDescriptor) mappedDescriptors.get(name);
        }
        if (result == null) {
            // not found, try to create it
            try {
                result =
                        new MappedPropertyDescriptor(name,
bean.getClass());
                if (mappedDescriptors == null) {
                    mappedDescriptors = new FastHashMap();
                    mappedDescriptorsCache.put(bean.getClass(),
                                                   mappedDescriptors);
                }
                mappedDescriptors.put(name, result);
            } catch (IntrospectionException ie) {
            }
        }
        return result;

Anyway...reviewing the code is a great way of trying to learn what this
does. I've been trying to test this out but I'm not even sure yet how to
properly test this yet. I'm assuming this will only be important if the
bean has getProperty() and setProperty() methods. 

-----Original Message-----
From: Bill Boland [mailto:bolandb@attbi.com] 
Sent: Tuesday, May 07, 2002 5:11 PM
To: commons-dev@jakarta.apache.org
Subject: PropertyUtils.getPropertyDescriptor() bug?

I was just trying to understand how the BeanUtils.populate() worked
which led me to understanding how the PropertyUtils.
getPropertyDescriptor() worked.

As I was looking at this, something didn't look right. It probably just
my unfamiliarity with this but the last few lines that put the result
into the cache didn't jive with the code above or the comment on the
cache. The lines:

        if (result != null) {
            mappedDescriptorsCache.put(name, result);
        }
        return result;

shouldn't this use the bean's class object as the key?

        if (result != null) {
            mappedDescriptorsCache.put(bean.getClass(), result);
        }
        return result;

not the name of the property. If so, this might help the performance a
bit.

I tried to look in the archives to see if this was a common
misconception but it seems to be down at the moment so I thought I'd
subscribe to the list and send this out.






--
To unsubscribe, e-mail:
<mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:commons-dev-help@jakarta.apache.org>




--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message