JDK-8144762 : Introspector - overloaded methods
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 8u40,9
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-10-30
  • Updated: 2016-12-20
  • Resolved: 2016-12-20
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 9
9Resolved
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
I tested on java 8 any release

ADDITIONAL OS VERSION INFORMATION :
Windows 7

A DESCRIPTION OF THE PROBLEM :
The changes made in the Introspector processPropertyDescriptors method are resposible for the following issue:

An index type property is not detected correctly in a subclass if it is using overloaded methods of the same property defined in a super class.


REGRESSION.  Last worked in version 7u80

ADDITIONAL REGRESSION INFORMATION: 
any java 8 version, did tests on the 66 and 45 updates

java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I have the following class structure

public class SuperClass {

    private String tagTemplate;

    public String getTagTemplate() {
        return tagTemplate;
    }

    public void setTagTemplate(String tagTemplate) {
        this.tagTemplate = tagTemplate;
    }
}


public class SubClass extends SuperClass {

    private Hashtable<Integer, Point> tagTemplateType = new Hashtable<Integer, Point>();

    public Point getTagTemplate(int index) {
        return tagTemplateType.get(index);
    }

    public void setTagTemplate(int index, Point tagType) {
        tagTemplateType.put(index, tagType);
    }
}


I run the following code

/**
 * @author Radu Barbos
 */
public class TestBeans {

    public static void main(String arg[]) {
        new TestBeans().test(SubClass.class);
    }

    private void test(Class<?> beanClass) {
        PropertyDescriptor descriptors[] = null;
        // Introspect the bean and cache the generated descriptors
        BeanInfo beanInfo = null;
        try {
            beanInfo = Introspector.getBeanInfo(beanClass);
        } catch (IntrospectionException e) {
            return;
        }
        descriptors = beanInfo.getPropertyDescriptors();
        for(PropertyDescriptor pd: descriptors) {
            System.out.println("--> " + pd.getName() + " " + (pd instanceof IndexedPropertyDescriptor));
        }
    }
}

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The expected output will be if the 'tagTemplate' property will be reprsented by a 'IndexedPropertyDescriptor' and the read/write methods should be the SubClass methods.

This behaviour is what happends in java 7
ACTUAL -
The 'tagTemplate' property is described by a 'PropertyDescriptor' and is represents the SuperClass methods, this is wrong and I'm extracting the SubClass properties.



REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
- do not use overloaded methods to represent index type properties in subclasses


Comments
This is caused by the fix of JDK-8034085. The provided example is incorrect. It has two different properties: one in the super class "TagTemplate" of type "String" and another TagTemplate of indexed of type "Point" in sub class. Since these properties contradict each other we can select any of them. To implement them properly the super class should use the array of points instead of String or the subclass should use another property name.
26-05-2016