BeansWrapper.populateClassMapWithPropertyDescriptor failing to create property descriptors

Donnchadh Ó Donnabháin <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <CADe7t4gnvq5kFQJn-aWUOm7HTnNkOfz6hrJNeLqfsbvjgSKGZw@mail.gmail.com>
  Hi guys,

This isn't a huge issue for us at the moment but it generates an ugly
warning and prevents us from using certain properties in our
FreeMarker.

Some of our domain model classes use generics, with some accessor
methods using type parameters. The java compiler generates bridge
methods in subclasses of our generic classes and these bridge methods
have a return type that doesn't match the setter in the parent class,
resulting in the following exception:


 WARN beans:116 - Failed creating a publicly-accessible property
descriptor for  ...
 java.beans.IntrospectionException: type mismatch between read and write methods
       at java.beans.PropertyDescriptor.findPropertyType(PropertyDescriptor.java:603)
       at java.beans.PropertyDescriptor.setWriteMethod(PropertyDescriptor.java:270)
       at java.beans.PropertyDescriptor.<init>(PropertyDescriptor.java:117)
       at freemarker.ext.beans.BeansWrapper.populateClassMapWithPropertyDescriptor(BeansWrapper.java:1255)
       at freemarker.ext.beans.BeansWrapper.populateClassMapWithBeanInfo(BeansWrapper.java:1152)
       at freemarker.ext.beans.BeansWrapper.populateClassMap(BeansWrapper.java:1072)
       at freemarker.ext.beans.BeansWrapper.introspectClassInternal(BeansWrapper.java:1010)
       at freemarker.ext.beans.BeansWrapper.introspectClass(BeansWrapper.java:969)
       at freemarker.ext.beans.BeanModel.<init>(BeanModel.java:140)
       at freemarker.ext.beans.StringModel.<init>(StringModel.java:90)
       at freemarker.ext.beans.StringModel$1.create(StringModel.java:75)
       at freemarker.ext.beans.BeansModelCache.create(BeansModelCache.java:45)
       at freemarker.ext.util.ModelCache.getInstance(ModelCache.java:115)
       at freemarker.ext.beans.BeansWrapper.wrap(BeansWrapper.java:468)
       at freemarker.template.DefaultObjectWrapper.handleUnknownType(DefaultObjectWrapper.java:144)
       at freemarker.template.DefaultObjectWrapper.wrap(DefaultObjectWrapper.java:128)
       at freemarker.template.WrappingTemplateModel.wrap(WrappingTemplateModel.java:134)
       at freemarker.template.SimpleHash.get(SimpleHash.java:224)


Maybe this code on line 1255 of BeansWrapper.java (FreeMarker 2.3.17):
                        pd = new PropertyDescriptor(pd.getName(),
                                publicReadMethod, pd.getWriteMethod());

could be replaced with something like this:

                        Method writeMethod = pd.getWriteMethod();
                        if (writeMethod != null &&
(pd.getWriteMethod().getParameterTypes().length != 1
                                ||
pd.getWriteMethod().getParameterTypes()[0] !=
publicReadMethod.getReturnType())) {
                            writeMethod = null;
                        }
                        pd = new PropertyDescriptor(pd.getName(),
                                publicReadMethod, writeMethod);

What do you think?

    Donnchadh

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.