JDK-8027648 : Type of overridden property is resolved incorrectly
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 7u40,8
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2013-10-31
  • Updated: 2014-04-23
  • Resolved: 2013-11-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 Other
8 b117Fixed port-stage-ppc-aixFixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)


A DESCRIPTION OF THE PROBLEM :
Introspector behavior has changed in 7u40 compared  to 7u25 - if return type of getter method can be casted to the return type of getter with same name defined in super-class, then Introspector uses return type of getter in parent class to determine property type.
As result, even if child bean class has a complete pair of getter and setter methods for property which type is descendant of another property defined in parent bean class, then such property is not recognized by Introspector - it uses type defined in super-class and doesn't link write method for property from child-class.

REGRESSION.  Last worked in version 7u25

ADDITIONAL REGRESSION INFORMATION:
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create two classes - A and B, where B extends A.
2. Create a base bean class - BeanA, with getter and setter pair for property 'data' of type A:
public void setData(A value)
public A getData()
3. Create a child bean class - BeanB (BeanB extends BeanA) with getter and setter pair for property 'data' of type B:
public void setData(B value)
public B getData()
4. Run Introspector on BeanB and get type for property 'data' and its read and write methods.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Property type: B
Read method: BeanB.getData()
Write method: BeanB.setData()
ACTUAL -
Property type: A
Read method: BeanB.getData()
Write method: BeanA.setData()

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
A.java:
public class A {}

B.java:
public class B extends A {}

BeanA.java:
public class BeanA
{
  public void setData(A value) {}
  public A getData() {return null;}
}

BeanB.java:
public class BeanB extends BeanA
{
  public void setData(B value) {}
  public B getData() {return null;}
}

Test.java:
import java.beans.*;
public class Test
{
  public static void main(String[] args)
  {
    try
    {
      for(PropertyDescriptor pd : Introspector.getBeanInfo(BeanB.class).getPropertyDescriptors())
      {
        if ("data".equals(pd.getName()))
        {
          System.out.println("Type: "+pd.getPropertyType().getName());
          System.out.println("Read: "+pd.getReadMethod());
          System.out.println("Write: "+pd.getWriteMethod());
        }
      }
    } catch (Throwable t)
    {
      t.printStackTrace();
    }
  }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
One can create custom BeanInfo class for BeanB to describe bean properties with correct type and links to correct getter and setter methods
Comments
http://cr.openjdk.java.net/~malenkov/8027648.8.0/
07-11-2013

- No, it is a regression introduced in 7u40 - Yes, it is affected jdk8
07-11-2013

SAM, - is it a regression introduced in 7u45? - is it affected jdk8?
05-11-2013

It is a regression after the 7189112 fix, which was also backported into 7u40.
31-10-2013

is it reproducible on jdk8 ?
31-10-2013