Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8132669

@BeanInfo: what is the priority of bean info if the annotated class extends some class having a user-defined BeanInfo class?

    XMLWordPrintable

Details

    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).

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              avstepan Alexander Stepanov
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated: