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

@beanProperty: should varargs be allowed as setter's argument?

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 9
    • client-libs

      Related to JDK-8154756.

      Not sure if an issue, but just in case.

      Please run the following code:

      import java.beans.*;

      public class Test {

          public static class X {

              @BeanProperty(
                  description = "test",
                  bound = true,
                  expert = false,
                  hidden = true,
                  preferred = false,
                  required = true,
                  visualUpdate = false)
              public void setX(Object ... u) { }

              public void addPropertyChangeListener(PropertyChangeListener l) {}
              public void removePropertyChangeListener(PropertyChangeListener l) {}
          }
          

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

              BeanInfo i = Introspector.getBeanInfo(X.class, Object.class);
              if (i == null) {
                  System.out.println("null bean info");
                  return;
              }

              PropertyDescriptor descriptors[] = i.getPropertyDescriptors();
              if (descriptors.length < 1) {
                  System.out.println("no descriptors found");
                  return;
              }

              PropertyDescriptor d = descriptors[0];
              System.out.println(
                  d.getShortDescription() + ", " +
                  d.isBound() + ", " + d.isExpert() + ", " +
                  d.isHidden() + ", " + d.isPreferred() + ", " +
                  (boolean) d.getValue("required") + ", " + (boolean) d.getValue("visualUpdate"));
          }
      }

      Output:
      test, true, false, true, false, true, false

      Should the vararg be considered as a valid argument type?

      for
      public void setX(Object o, Object ... u) { }
      the output is as expected ("no descriptors found")

      So that may be some imbalance here.

      Plus in principle the user can pass the empty varargs list: (new X()).setX();

      It is also unclear how to interpret vararg setter: as indexed? non-indexed? and how, e.g., it should coexist with indexed and/or non-indexed seeters

            Unassigned Unassigned
            avstepan Alexander Stepanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: