Details
-
Bug
-
Resolution: Fixed
-
P3
-
7u40, 8
-
b06
-
b117
Backports
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8028855 | port-stage-ppc-aix | Sergey Malenkov | P3 | Resolved | Fixed | master |
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
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
Attachments
Issue Links
- backported by
-
JDK-8028855 Type of overridden property is resolved incorrectly
-
- Resolved
-
- relates to
-
JDK-7189112 java.beans.Introspector misses write methods
-
- Resolved
-
-
JDK-8027906 BeanInfo.getPropertyDescriptors() can return property with wrong type
-
- Closed
-
-
JDK-8030123 java/beans/Introspector/Test8027648.java fails
-
- Resolved
-
-
JDK-8039776 Introspector throws NullPointerException for subclasses' mismatched get/setter
-
- Resolved
-
-
JDK-8041630 Exception while constructing BeanInfo using java.beans.Introspector
-
- Closed
-
(1 relates to)