The beanutils package do not contain any notion of dynamic class loading.
It is very possible that in an application the beanutils package will be in
a class loader that is a parent of the beans that it loads.
In that case, there can potentially be more than one instance of the same
bean class (coming from different children).
Also when the classes are reloading (by replacing the child class loaders),
the cache still contains instances of the old Class objects.
This prevents garbage collection of the old class loader. It cannot be
garbage collected unless all its classes are freed.

As a minimum, the descriptor cache (PropertyUtils.descriptorsCache) should
use the Class object of the bean as the key to the table and not the actual
name of the class (which is a String).

The code should be something like:

// In PropertyUtils:

    public static PropertyDescriptor[] getPropertyDescriptors(Object bean) {

        if (bean == null)
            throw new IllegalArgumentException("No bean specified");

        // Look up any cached descriptors for this bean class
        PropertyDescriptor descriptors[] = null;
        descriptors =
            (PropertyDescriptor[]) descriptorsCache.get(bean.getClass());
        if (descriptors != null)
            return (descriptors);

        // Introspect the bean and cache the generated descriptors
        BeanInfo beanInfo = null;
        try {
            beanInfo = Introspector.getBeanInfo(bean.getClass());
        } catch (IntrospectionException e) {
            return (new PropertyDescriptor[0]);
        }
        descriptors = beanInfo.getPropertyDescriptors();
        if (descriptors == null)
            descriptors = new PropertyDescriptor[0];
        descriptorsCache.put(bean.getClass(), descriptors);
        return (descriptors);

    }

Reply via email to