JDK-8132669 : @BeanInfo: what is the priority of bean info if the annotated class extends some class having a user-defined BeanInfo class?
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 9,10
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2015-07-30
  • Updated: 2021-07-13
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
Relates :  
Relates :  
Relates :  
Description
The issue is quite similar to JDK-8132565, but here the base class has a user-defined BeanInfo class and the child class is annotated. The case is not described in the spec. unambiguously: "annotation is not used if the annotated class has a corresponding user-defined BeanInfo class". Anyway, the following example demonstrates the buggy behavior (similar to JDK-8132565):

import java.beans.*;

public class InhTest {

    @JavaBean(description = "C Description")
    public static class C extends CBase {
        private int x;
        @BeanProperty(
            hidden    = false,
            preferred = false,
            expert    = 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;
        public int getX() { return x; }
        public void setX(int v) { x = v; }
    }

    
    public static class CBaseBeanInfo extends SimpleBeanInfo {

        @Override
        public BeanDescriptor getBeanDescriptor() {
            BeanDescriptor d = new BeanDescriptor(CBase.class, null);
            d.setShortDescription("CBase Description");
            return d;
        }

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

            try {
                p[0] = new PropertyDescriptor ("x", CBase.class, "getX", null);
                p[0].setHidden(true);
                p[0].setPreferred(true);
                p[0].setExpert(true);
                p[0].setShortDescription("CBase 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(CBase.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(d.isExpert());
        System.out.println("");
    }


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

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


The output (Ubuntu 14.04 Linux, JDK9 b73):

test CBase:
CBase x Description
true
true
true

test C:
C x Description
true
true
true


The output for "C" is inconsistent (description from C, hidden/preferred/expert from the base class).
Comments
Targeted to 10 as an issue introduced in 8u or 9
17-02-2017

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

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

SQE: OK to defer
12-08-2016

So it seems the issue is somehow connected to JDK-8132067
30-07-2015

Interesting: if remove "static" from declarations of C, CBase and CBaseBeanInfo, then the output is: test CBase: x false false false test C: C x Description false false false - now the results for CBase are incorrect.
30-07-2015