United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6528714 : Introspector uses interface signature in property descriptor

Details
Type:
Bug
Submit Date:
2007-02-27
Status:
Closed
Updated Date:
2013-07-18
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
client-libs
OS:
windows_xp
Sub-Component:
java.beans
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Duplicate:
Relates:
Relates:
Relates:

Sub Tasks

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

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

A DESCRIPTION OF THE PROBLEM :
I have a generic interface that defines a getter method that uses the generic type.

When I Introspect a a class that implements this method, the Propertydescriptor for the method claims that the property type is Object when it should return the actual type declared in the class.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the test case:

javac NameBean.java
java NamedBean


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected to see:
Property class: class java.lang.Class
Property name: class java.lang.String

Which is what I get if I compile and run using :
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
ACTUAL -
What I get is:
Property class: class java.lang.Class
Property name: class java.lang.Object

I also get the same result when I run this with the latest build:
java version "1.6.0_01-ea"
Java(TM) SE Runtime Environment (build 1.6.0_01-ea-b03)
Java HotSpot(TM) Client VM (build 1.6.0_01-ea-b03, mixed mode)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Named.java:

public interface Named<T> {

  public T getName();

}

NamedBean.java:
import java.beans.*;

class NamedBean implements Named<String> {
  private String myName;

  public String getName() {
     return myName;
  }

  public void setName(String name) {
     myName = name;
  }

  public static void main(String[] args) throws Exception {
    BeanInfo bi = Introspector.getBeanInfo(NamedBean.class);
    for (PropertyDescriptor d: bi.getPropertyDescriptors()) {
      System.out.println("Property "+d.getName()+": "+d.getPropertyType());
    }
  }

}


---------- END SOURCE ----------

                                    

Comments
EVALUATION

Java 5 allow to use narrow return types in subclasses.
Special synthetic method is generated to support this feature.
We should skip synthetic methods when determining the properties of the class.
                                     
2007-05-25



Hardware and Software, Engineered to Work Together