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

MenuItem#buildEventDispatchChain() ignores return values

XMLWordPrintable

    • x86_64
    • windows_10

      A DESCRIPTION OF THE PROBLEM :
      In method buildEventDispatchChain of class javafx.controls.MenuItem, the method buildEventDispatchChain(tail) is called on the parent popup and on the parent menu (if available).
      In both cases, the returned chain objects are ignored:

      /** {@inheritDoc} */
      @Override public EventDispatchChain buildEventDispatchChain(EventDispatchChain tail) {
      // FIXME review that these are configure properly
      if (getParentPopup() != null) {
      getParentPopup().buildEventDispatchChain(tail); // ERROR: returned chain is ignored!
      }

      if (getParentMenu() != null) {
      getParentMenu().buildEventDispatchChain(tail); // ERROR: returned chain is ignored!
      }

      return tail.prepend(eventHandlerManager);
      }

      Instead, the returned chains should be used as new tails:

      /** {@inheritDoc} */
      @Override public EventDispatchChain buildEventDispatchChain(EventDispatchChain tail) {
      // FIXME review that these are configure properly
      if (getParentPopup() != null) {
      tail = getParentPopup().buildEventDispatchChain(tail);
      }

      if (getParentMenu() != null) {
      tail = getParentMenu().buildEventDispatchChain(tail);
      }

      return tail.prepend(eventHandlerManager);
      }

      The reason why the current implementation works in spite of this bug is, that the default implementation of EventDispatchChain, class com.sun.javafx.event.EventDispatchChainImpl, always changes itself and returns 'this' when a dispatcher is appended or preprended to it - which is allowed, but not required according to the API doc.

      Some (future) implementation of EventDispatchChain might instead return a different chain, in which case the current implementation of MenuItem#buildEventDispatchChain would not work as expected any more.


      FREQUENCY : always


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: