JDK-8132703 : @BeanProperty: invalid info in case of incomplete (or arbitrary) getter / setter name
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 9
  • 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 :  
Description
(sorry, the initial bug was fully rewritten)


This is some boundary case. As it follows from the bean spec (not sure if it is the latest one: http://download.oracle.com/otndocs/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/ ), "accessor methods can have arbitrary names", but it is recommended to use something like "getXxx", where "xxx" is a property name.

Here is some degenerate case:

    public static class C {
        private final int x = 42;
        @BeanProperty(expert = true, description = "TEST")
        public int get() { return x; }
    } 
    
    public static void main(String[] args) throws Exception {
        
        BeanInfo i = Introspector.getBeanInfo(C.class, Object.class);
        
        if (i.getPropertyDescriptors().length > 0) {
            PropertyDescriptor d = i.getPropertyDescriptors()[0];
            System.out.println(d.getShortDescription());
            System.out.println(d.isExpert());
        } else {
            System.out.println("no properties!");
        }
    }

Output (Win 7, JDK9 b72):
no properties!

please try to change "get" to "get_" -> the output is as expected:
TEST
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.
12-08-2016

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

The same issue if the getter / setter name does not start with lower-case "get"/"set": public static class C { private final int x = 42; @BeanProperty(expert = true, description = "TEST") public int GetX() { return x; } } Out: "no properties!" in case of the user-defined BeanInfo: 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].setExpert(true); p[0].setShortDescription("TEST"); } catch(IntrospectionException e) { e.printStackTrace(); } return p; } @Override public EventSetDescriptor[] getEventSetDescriptors() { return new EventSetDescriptor[0]; } @Override public MethodDescriptor[] getMethodDescriptors() { return new MethodDescriptor[0]; } @Override public int getDefaultPropertyIndex() { return -1; } @Override public int getDefaultEventIndex() { return -1; } @Override public java.awt.Image getIcon(int iconKind) { return null; } } Out: TEST true (as expected)
30-07-2015

Note that in case of user-defined BeanInfo we can use short names like "get" and "set": public class PropNameTest { public static class C { private final int x = 42; //@BeanProperty(expert = true, description = "TEST") public int get() { return x; } } 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, "get", null); p[0].setExpert(true); p[0].setShortDescription("TEST"); } catch(IntrospectionException e) { e.printStackTrace(); } return p; } @Override public EventSetDescriptor[] getEventSetDescriptors() { return new EventSetDescriptor[0]; } @Override public MethodDescriptor[] getMethodDescriptors() { return new MethodDescriptor[0]; } @Override public int getDefaultPropertyIndex() { return -1; } @Override public int getDefaultEventIndex() { return -1; } @Override public java.awt.Image getIcon(int iconKind) { return null; } } public static void main(String[] args) throws Exception { BeanInfo i = Introspector.getBeanInfo(C.class, Object.class); if (i.getPropertyDescriptors().length > 0) { PropertyDescriptor d = i.getPropertyDescriptors()[0]; System.out.println(d.getShortDescription()); System.out.println(d.isExpert()); } else { System.out.println("no properties!"); } } } Output: TEST true (as expected)
30-07-2015