JDK-8132163 : @BeanProperty: Bean info depends on a getter return type / setter argument type
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 9
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2015-07-22
  • 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
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
Please run:

import java.beans.*;

public class Test {

    public static class C {
        private int x;

        @BeanProperty(
            hidden    = true,
            preferred = true,
            description = "xxx"
            )
        public   void setX(int i) { x = i; }
        public double getX()      { return x; }
    }


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

        BeanInfo i = Introspector.getBeanInfo(C.class, Object.class);
        PropertyDescriptor d = i.getPropertyDescriptors()[0];

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


note: here getX() returns double instead of int.

Output (JDK9 b73, linux-64): 

x
false
false
 - just default values.

If change "double getX()" to "int getX()" then the output will be as expected:

xxx
true
true
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

SQE: OK 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

please update test/java/beans/Introspector/BeanPropertyTest.java after the bug fix
21-04-2016

The same for setter, e.g.: public static class C { private int x; @BeanProperty(hidden = true, preferred = true, description = "xxx") public void setX(Integer i) { x = i; } public int getX() { return x; } } => invalid output or in case if the setter has more than one parameter: public static class C { private int x; @BeanProperty(hidden = true, preferred = true, description = "xxx") public void setX(int... i) { x = i[0]; } public int getX() { return x; } } => invalid output (but maybe all the cases mentioned contradict some JavaBean conventions). interesting: extra getter parameters do not affect the result: public static class C { private int x; @BeanProperty(hidden = true, preferred = true, description = "xxx") public void setX(int i) { x = i; } public int getX(Object... dummy) { return x; } } => expected output And: this is the most strange case: public static class C { private int x; @BeanProperty(hidden = true, preferred = true, description = "xxx") public void setX(int... i) { x = i[0]; } public int getX(Object... dummy) { return x; } } => the expected output! (extra getter and setter parameters in some non-obvious way "compensate" each other)
23-07-2015

The bug is questionable, but please note that if there exists the user-defined BeanInfo class for C, like public static class CBeanInfo extends SimpleBeanInfo { @Override public BeanDescriptor getBeanDescriptor() { return new BeanDescriptor(C.class, null); } @Override public PropertyDescriptor[] getPropertyDescriptors() { PropertyDescriptor[] p = new PropertyDescriptor[1]; try { p[0] = new PropertyDescriptor ("x", C.class, "getX", null); p[0].setHidden(true); p[0].setPreferred(true); p[0].setShortDescription("xxxxx"); } 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(C.class.getMethod("setX", new Class[] {int.class})); m[0].setDisplayName(""); } catch( Exception 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; } } then the output is correct: xxxxx true true (so probably it may be considered as a backward compatibility issue)
22-07-2015