JDK-8027906 : BeanInfo.getPropertyDescriptors() can return property with wrong type
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 7u25
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_7
  • Submitted: 2013-09-04
  • Updated: 2013-11-06
  • Resolved: 2013-11-06
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b16)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

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

This problem is similar to bug JDK-6788525

Unfortunately it can still occur in JRE7 but is not reproducable. It depends on the order of the methods returned by "Method[] java.lang.Class.getMethods()" if the result is correct or not.

The javadoc of this method says "... The elements in the array returned are not sorted and are not in any particular order..." but the Introspector uses the order to create the property descriptors. Therefore it can happen that a wrong property descriptor is returned.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
unfortunately this bug is non-deterministic. most times the result is correct but unfortunately not always!

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 rarely.

---------- BEGIN SOURCE ----------
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;

interface Super<T> {
public T getFoo();

public void setFoo(T t);
}

class Sub implements Super<String> {
public String getFoo() {
return null;
}

public void setFoo(String t) {
}
}

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
", prop.getName(), prop.getPropertyType());
}
}
}

---------- END SOURCE ----------
Comments
It is hard to reproduce. Seems it duplicates the 8027905 issue.
06-11-2013