JDK-6794807 : Introspecting returns incorrect PropertyDescriptor for overriden getter.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2009-01-16
  • Updated: 2013-07-18
  • Resolved: 2013-07-18
Related Reports
Duplicate :  
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, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Introspecting returns incorrect PropertyDescriptor for overriden getter in case when child getter has more specific return type. In this case PropertyDescriptor of parent class is returned instead.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See source code attached bellow.




EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
App$FooChild
ACTUAL -
App$FooParent

REPRODUCIBILITY :
This bug can be reproduced always.

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

public class App {

	public static class FooParent {  }
	public static class FooChild extends FooParent {  }

	public static class HierarchyParent {
		public FooParent getFoo() { return new FooParent(); }
	}
	public static class HierarchyChild extends HierarchyParent {
		@Override
		public FooChild getFoo() { return new FooChild(); }
	}

	public static void main(String[] args) throws Exception {
		BeanInfo info = Introspector.getBeanInfo(HierarchyChild.class);
		for (PropertyDescriptor desc : info.getPropertyDescriptors()) {
			if ("foo".equals(desc.getName())) {
				//result should be App$FooChild
				System.out.println(desc.getPropertyType());
				break;
			}
		}
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use simple reflection instead BeanInfo.

Comments
EVALUATION Bean Introspection should support Generics.
21-01-2009