United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6788525 : BeanInfo.getPropertyDescriptors() gets mixed up with generic bridge methods

Details
Type:
Bug
Submit Date:
2008-12-23
Status:
Closed
Updated Date:
2016-09-06
Project Name:
JDK
Resolved Date:
2016-09-06
Component:
client-libs
OS:
windows_xp
Sub-Component:
java.beans
CPU:
x86
Priority:
P2
Resolution:
Cannot Reproduce
Affected Versions:
6u10,7,8,9
Fixed Versions:

Related Reports
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.6.0_05"
Java(TM) SE Runtime Environment (build 1.6.0_05-b13)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [vers??o 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
If a JavaBean class has properties that are inherited from a generic superclass, java.beans.BeanInfo will find a PropertyDescriptor corresponding to synthetic bridge methods and not the actual typed methods.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a generic superclass with a property (getter/setter pair) whose type is a type parameter. Create a parametrized subclass (a subclass with actual type arguments). Use java.beans.Introspector.getBeanInfo() to get a BeanInfo representing the subclass. Notice that the PropertyDescriptor that would correspond to the property (meaning, it's name is the same as the name of the property) has a type equal to the upper bound of the type parameter in the superclass, where we would expect it to have the corresponding type argument defined on the subclass.

This behavior is likely due to the Introspector finding synthetic bridge methods for the getter and setter instead of the actual methods.

(The Expected and Actual results below refer to the output of the sample code)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
class of type class java.lang.Class
foo of type class java.lang.String

ACTUAL -
class of type class java.lang.Class
foo of type class java.lang.Object


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.beans.*;

class Super<T> {
	public T getFoo() {return null;}
	public void setFoo(T t) {}
}

class Sub extends Super<String> {
}

public class Main {
	public static void main(String[] args) throws IntrospectionException {
		BeanInfo beanInfo = Introspector.getBeanInfo(Sub.class);
		
		PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
		
		for (PropertyDescriptor prop : propertyDescriptors) {
			System.out.printf("%s of type %s\n", prop.getName(), prop.getPropertyType());
		}
	}
}
---------- END SOURCE ----------

                                    

Comments
>>This was a major problem in Java 6. In Java 7, it seems to have been fixed except that the ordering of bridge methods in a class file is random, so a call to Introspector.getBeanInfo() sometimes returns the correct methods, but sometimes the incorrect bridge methods.

The random behaviour was fixed in jdk9 by 8156043, so right now the bug above should been fixed or always reproducible. Can the customer check the latest version of jdk9?  
                                     
2016-08-29
CAP member has confirmed  that they just tested Java 9-ea+133 with all of their TypeResolver workaround code removed, and it functions as desired. 

                                     
2016-08-29
Still pending a fix for customer as high priority issue. Targeted to 9.
                                     
2016-08-17
This is a bug for 9
                                     
2016-02-26
should be pre-estimated to implement in JDK 9
Still pending to re-evaluate
                                     
2015-12-09



Hardware and Software, Engineered to Work Together