United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6473468 : RFE: PropertyDescriptor should support getGenericPropertyType() method

Details
Type:
Enhancement
Submit Date:
2006-09-21
Status:
Open
Updated Date:
2011-02-16
Project Name:
JDK
Resolved Date:
Component:
client-libs
OS:
windows_2003
Sub-Component:
java.beans
CPU:
x86
Priority:
P5
Resolution:
Unresolved
Affected Versions:
6
Targeted Versions:

Related Reports
Relates:

Sub Tasks

Description
A DESCRIPTION OF THE REQUEST :
When the type of a  property is a generic collection type (like List<String>), the existing PropertyDescriptor.getPropertyType() method returns only the "raw" property type of "List".  What is needed is a method like this:

    Type getPropertyGenericType();

that would return the full generic type (List<String>) as obtained from
  getReadMethod()..getGenericReturnType();
or
  getWriteMethod().getGenericParameterTypes()[0];

The other "Descriptor" types should probably have the same enhancement.  Eg, "BeanDescriptor" should have a new method:
    Type getBeanGenericClass();
and so on.


JUSTIFICATION :
When generics were introduced, the "java.lang.reflect.Field" class added a "getGenericType()" type to compliment the existing "getType()" method.
This RFE would just be adding the same capability to the "PropertyDescriptor" class.



CUSTOMER SUBMITTED WORKAROUND :
The only work around is to access the same information through the "java.lang.reflect.*" classes, which defeats the purpose of having the java.beans package in the first place.

                                    

Comments
EVALUATION

We should not fix this bug because getter and setter can be declared in different classes.
The following types will be different in such case:
 Type getter = propertyDescriptor.getReadMethod().getGenericReturnType();
 Type setter = propertyDescriptor.getWriteMethod().getGenericParameterTypes()[0];
So we can't decide what type is expected from the suggested method:
 Type getPropertyGenericType();
                                     
2007-05-25
WORK AROUND

It is often possible to use propertyDescriptor.getReadMethod().getGenericReturnType() or propertyDescriptor.getWriteMethod().getGenericParameterTypes()[0].
                                     
2006-09-21
EVALUATION

I think it is impossible while such info is not accesible via reflection.
                                     
2006-09-21



Hardware and Software, Engineered to Work Together