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

@BeanProperty: inconsistent inheritance behavior

    XMLWordPrintable

    Details

      Description

      Please run the following code:

      import java.beans.*;

      public class InhTest {

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

          
          public static class D extends DBase {
              private int x;
              @Override
              public int getX() { return x; }
              @Override
              public void setX(int v) { x = v; }
          }

          public static class DBeanInfo extends SimpleBeanInfo {

              @Override
              public BeanDescriptor getBeanDescriptor() {
                  return new BeanDescriptor(D.class, null);
              }

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

                  try {
                      p[0] = new PropertyDescriptor ("x", D.class, "getX", null);
                      p[0].setHidden(false);
                      p[0].setPreferred(false);
                      p[0].setShortDescription("D 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(D.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; }
          }
          
          public static class DBase {
              private int x;
              public int getX() { return x; }
              public void setX(int v) { x = v; }
          }

          
          public static class DBaseBeanInfo extends SimpleBeanInfo {

              @Override
              public BeanDescriptor getBeanDescriptor() {
                  return new BeanDescriptor(DBase.class, null);
              }

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

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


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

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


      Output (Win 7, JDK9b72):

      test C:
      C x Description
      true
      true

      test D:
      D x Description
      false
      false


      So it seems that the base description for C was overwritten; but the "hidden" and "preferred" info - was not.

      the expected (?) output for C:
      test C:
      C x Description
      false
      false
      (as for D)

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              avstepan Alexander Stepanov
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated: