[JSR308] a problem with beans and annotations

Eamonn McManus Eamonn.McManus at Sun.COM
Wed Sep 24 08:18:09 EDT 2008


There has never been any requirement for a JavaBean to have a field corresponding to each property. 
So I think trying to introduce new semantics based on the type of that field would be too radical a 

RFE 6473468 <http://bugs.sun.com/view_bug.do?bug_id=6473468> asks for a 
PropertyDescriptor.getPropertyGenericType() method. I do not know what the plans for that RFE are, 
but as noted in the Work Around (and in your message) you can often use 
propertyDescriptor.getReadMethod().getGenericReturnType(). You can also use that technique to get 
annotations on the getter method.

Since properties are often defined by a getter and a setter and there can be awkwardness if the 
return type of the former is not exactly the same as the parameter type of the latter, and in 
particular if the type annotations are not the same.

Éamonn McManus · JMX Spec Lead · http://weblogs.java.net/blog/emcmanus/

David Goodenough wrote:
> Currently the Introspector code that fetches the Class object for a 
> property (as expressed in PropertyDescriptor) picks up the Type from
> the return type of the getter. 
> In the old days (before annotations) this was fine, as the type returned
> by the getter was the same as the type of the arguement to the setter
> and was also the same as the underlying property.  But with annotations
> this changes.  
> Obtaining the value for the return type of the getter and the arguement
> type for the setter can be achieved from the getReadMethod and 
> getWriteMethod method so any annotations on those are accesible.  But
> the annotations on the underlying field are not available.
> So either a new method needs to be added to the PropertyDescriptor class
> which returns the field type (where there is a corresponding field, null if 
> there is no underlying field) or the definition of getPropertyType needs to be 
> changed and it should return the field type.
> David 
> _______________________________________________
> JSR308 mailing list
> JSR308 at lists.csail.mit.edu
> https://lists.csail.mit.edu/mailman/listinfo/jsr308

More information about the JSR308 mailing list