JDK-8132565 : @BeanProperty: inconsistent inheritance behavior
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 8,9,10,11,13,14,15
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2015-07-29
  • Updated: 2024-06-24
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.
Other
tbdUnresolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Please run the following code:

import java.beans.*;

public class InhTest {

    public static class C extends CBase {
        private int x;
        @BeanProperty(
            hidden = false,
            preferred = false,
            description = "C x Description"
            )
        @Override
        public int getX() { return x; }
        @Override
        public void setX(int v) { x = v; }
    }
    
    public static class CBase {
        private int x;
        @BeanProperty(
            hidden = true,
            preferred = true,
            description = "CBase x Description"
            )
        public int getX() { return x; }
        public void setX(int v) { x = v; }
    }

    
    public static class D extends DBase {
        private int x;
        @Override
        public int getX() { return x; }
        @Override
        public void setX(int v) { x = v; }
    }

    public static class DBeanInfo extends SimpleBeanInfo {

        @Override
        public BeanDescriptor getBeanDescriptor() {
            return new BeanDescriptor(D.class, null);
        }

        @Override
        public PropertyDescriptor[] getPropertyDescriptors() {
            PropertyDescriptor[] p = new PropertyDescriptor[1];

            try {
                p[0] = new PropertyDescriptor ("x", D.class, "getX", null);
                p[0].setHidden(false);
                p[0].setPreferred(false);
                p[0].setShortDescription("D x Description");
            }
            catch(IntrospectionException e) {
                e.printStackTrace();
            }
            return p;
        }

        @Override
        public EventSetDescriptor[] getEventSetDescriptors() { return new EventSetDescriptor[0]; }
        @Override
        public MethodDescriptor[] getMethodDescriptors() {
            MethodDescriptor[] m = new MethodDescriptor[1];
            try {
                m[0] = new MethodDescriptor(D.class.getMethod("setX", new Class[] {int.class}));
                m[0].setDisplayName("");
            }
            catch( NoSuchMethodException | SecurityException e) {}
            return m;
        }

        @Override
        public int getDefaultPropertyIndex() { return -1; }
        @Override
        public int getDefaultEventIndex() { return -1; }
        @Override
        public java.awt.Image getIcon(int iconKind) { return null; }
    }
    
    public static class DBase {
        private int x;
        public int getX() { return x; }
        public void setX(int v) { x = v; }
    }

    
    public static class DBaseBeanInfo extends SimpleBeanInfo {

        @Override
        public BeanDescriptor getBeanDescriptor() {
            return new BeanDescriptor(DBase.class, null);
        }

        @Override
        public PropertyDescriptor[] getPropertyDescriptors() {
            PropertyDescriptor[] p = new PropertyDescriptor[1];

            try {
                p[0] = new PropertyDescriptor ("x", DBase.class, "getX", null);
                p[0].setHidden(true);
                p[0].setPreferred(true);
                p[0].setShortDescription("DBase x Description");
            }
            catch(IntrospectionException e) {
                e.printStackTrace();
            }
            return p;
        }

        @Override
        public EventSetDescriptor[] getEventSetDescriptors() { return new EventSetDescriptor[0]; }
        @Override
        public MethodDescriptor[] getMethodDescriptors() {
            MethodDescriptor[] m = new MethodDescriptor[1];
            try {
                m[0] = new MethodDescriptor(DBase.class.getMethod("setX", new Class[] {int.class}));
                m[0].setDisplayName("");
            }
            catch( NoSuchMethodException | SecurityException e) {}
            return m;
        }

        @Override
        public int getDefaultPropertyIndex() { return -1; }
        @Override
        public int getDefaultEventIndex() { return -1; }
        @Override
        public java.awt.Image getIcon(int iconKind) { return null; }
    }
    

    
    static void Test(Class<?> c) throws Exception {
        System.out.println("test " + c.getSimpleName() + ":");
        BeanInfo i = Introspector.getBeanInfo(c, Object.class);
        PropertyDescriptor d = i.getPropertyDescriptors()[0];

        System.out.println(d.getShortDescription());
        System.out.println(d.isHidden());
        System.out.println(d.isPreferred());
        System.out.println("");
    }


    public static void main(String[] args) throws Exception {

        Test(C.class);
        Test(D.class);
    }
}


Output (Win 7, JDK9b72):

test C:
C x Description
true
true

test D:
D x Description
false
false


So it seems that the base description for C was overwritten; but the "hidden" and "preferred" info - was not.

the expected (?) output for C:
test C:
C x Description
false
false
(as for D)
Comments
Targeted to 10 as an issue introduced in 8u or 9
17-02-2017

Approved by component triage team to defer
15-08-2016

SQE: OK to defer
15-08-2016

9-client-defer-candidate: There is no resource to fix it in jdk9.
12-08-2016

please update test/java/beans/Introspector/InheritanceBeanPropertyTest.java after the fix (and check that the tests from test/java/beans/Introspector/8132566/* pass)
29-04-2016

It should be also mentioned that we seemingly shouldn't inherit the property description data when overriding the annotated accessor. In fact - we did. To reproduce, please use the attached "Test.java"; the output will be (JDK9 b115 + Win 7): === testing C1 === x isExpert = false isPreferred = false required = false visualUpdate = false === testing C2 === x isExpert = false isPreferred = false required = false visualUpdate = false === testing C3 === annotated getter isExpert = true isPreferred = true required = false visualUpdate = false The expected output for C3 is the same as for C1, C2 (i.e. default).
27-04-2016

Please note that the enumeration values are overridden correctly.
04-08-2015