Java Mailing List Archive

http://www.junlu.com/

Home » FreeMarker-user »

Re: [FreeMarker-user]
 BeansWrapper.populateClassMapWithPropertyDescriptor failing
 to create property descriptors

Attila Szegedi

2011-11-15

Replies: Find Java Web Hosting

Author LoginPost Reply
Actually, I don't think we use write methods at all, do we? FreeMarker is only ever reading properties, never writing them. I'm not even sure why I wrote the code so that it's putting the write methods into the property descriptors; I guess we could just replace them with nulls and thus emulate read-only properties.

Attila.

On Nov 15, 2011, at 7:26 AM, Donnchadh Ó Donnabháin wrote:

> 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
> _______________________________________________
> FreeMarker-user mailing list
> FreeMarker-user@(protected)
> https://lists.sourceforge.net/lists/listinfo/freemarker-user


------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
FreeMarker-user mailing list
FreeMarker-user@(protected)
https://lists.sourceforge.net/lists/listinfo/freemarker-user
©2008 junlu.com - Jax Systems, LLC, U.S.A.