JDK-8131342 : new @BeanProperty annotation: could we specify more than one per bean?
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2015-07-15
  • Updated: 2016-04-26
  • Resolved: 2015-07-29
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
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
Please run the following code:

import java.beans.*;

public class EnumTest {
    
    public class Bean {

        private int a;
        private int b;

        @BeanProperty(
                description = "A DESCRIPTION",
                enumerationValues = {
                    "javax.swing.SwingConstants.TOP"}
                )
        public   void setA(int v)    { a = v; }
        public    int getA()         { return a; }

        @BeanProperty(
                description = "B DESCRIPTION",
                enumerationValues = {
                    "javax.swing.SwingConstants.BOTTOM"}
                )
        public   void setB(int v) { b = v; }
        public double getB()      { return b; }
    }
    
    static void printEnum(PropertyDescriptor d) {
        Object en = d.getValue("enumerationValues");
        if (en == null) {
            System.out.println("null enumeration");
        } else {
            Object tmp[] = (Object []) en;
            for (Object o: tmp) {
                System.out.print(o + " ");
            }
            System.out.println("");
        }
    }


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

        BeanInfo i = Introspector.getBeanInfo(Bean.class, Object.class);
        PropertyDescriptor[] ds = i.getPropertyDescriptors();
        for (PropertyDescriptor d: ds) {
            System.out.println(d.getShortDescription());
            printEnum(d);
        }
    }
}


Expected (?) output:

A DESCRIPTION
TOP 1 javax.swing.SwingConstants.TOP 
B DESCRIPTION
BOTTOM 3 javax.swing.SwingConstants.BOTTOM 


Actual output:

A DESCRIPTION
TOP 1 javax.swing.SwingConstants.TOP 
b
null enumeration



Could we use @BeanProperty more than once per bean? If no then how is it decided what property is top-priority?


Checked with JDK9 b72

Comments
looking more carefully at the test: the root cause of the issue is not the presence of two properties simultaneously, but inconsistency of the b's getter return type (double) and setter argument type (int). So it probably should be considered as a duplicate for JDK-8132163
29-07-2015

the same for other feature descriptor fields like "hidden", "expert", "preferred" etc.
15-07-2015

Discovered while working on JDK-8131055
15-07-2015

Please note that if define BeanInfo by creating the corresponding class, we'll get the "expected" output.
15-07-2015