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

@BeanProperty: should setting 'bound' field to false in the overriden property prevent sending PropertyChangeEvent?

XMLWordPrintable

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

      Not sure if a bug, but just in case...

      Please run the following code:


      import java.beans.*;
      import java.lang.reflect.Method;
      import javax.swing.JButton;

      public class ListenerTest {

          private static class Child extends JButton {

              @BeanProperty(bound = false, description = "child's text")
              @Override
              public void setText(String text) { super.setText(text); }
          }

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

              Child child = new Child();
              child.addPropertyChangeListener("text", (PropertyChangeEvent e) -> {
                  System.out.println("\n>>> LISTENER: " + e.getPropertyName() + " changed");
              });

              Method m = child.getClass().getMethod("setText", String.class);
              BeanProperty p = (BeanProperty) m.getAnnotation(BeanProperty.class);
              System.out.println("setText(), bound = " + p.bound() + ":\n" + p.toString());

              child.setText("ABC");
          }
      }


      The output (JDK9 b115 + Win. 7):

      setText(), bound = false:
      java.beans.BeanProperty(expert=false, hidden=false, visualUpdate=false, bound=false, enumerationValues=[], description=child's text, preferred=false, required=false)

      >>> LISTENER: text changed

      A bound property notifies listeners when its value changes. Here the child's text property is explicitly annotated as _not_ a bound. Should this prevent from receiving the event or this is just some information for the user?

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

              Created:
              Updated: