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

Adding EventFilter to stage cause ClassCastException in dispatchEvent

    XMLWordPrintable

Details

    • x86_64
    • windows_10

    Description

      A DESCRIPTION OF THE PROBLEM :
      Adding an event filter on stage cause ClassCastException in dispatchEvent when startEdit/cancelEdit is called on a treeCell

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Launch the attached app.
      Expand "MyCompany Human Resources" node
      Expand "Sales Departement" node
      Double Click on the leaf "Ethan Williams"


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The cell should enter in editing mode
      ACTUAL -
      => ClassCastException


      Exception in thread "JavaFX Application Thread" java.lang.ClassCastException: javafx.stage.Stage cannot be cast to javafx.scene.control.TreeView
      at javafx.scene.control.TreeView$EditEvent.getSource(TreeView.java:1196)
      at javafx.scene.control.TreeView$EditEvent.getSource(TreeView.java:1165)
      at com.sun.javafx.event.EventHandlerManager.fixEventSource(EventHandlerManager.java:246)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:237)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
      at javafx.event.Event.fireEvent(Event.java:198)
      at javafx.scene.Node.fireEvent(Node.java:8413)
      at javafx.scene.control.TreeCell.startEdit(TreeCell.java:372)
      at javafx.scene.control.cell.TextFieldTreeCell.startEdit(TextFieldTreeCell.java:191)
      at javafx.scene.control.TreeCell.updateEditing(TreeCell.java:575)
      at javafx.scene.control.TreeCell.lambda$new$255(TreeCell.java:144)
      at javafx.beans.WeakInvalidationListener.invalidated(WeakInvalidationListener.java:83)
      at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:349)
      at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
      at javafx.beans.property.ReadOnlyObjectPropertyBase.fireValueChangedEvent(ReadOnlyObjectPropertyBase.java:74)
      at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:102)
      at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
      at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
      at javafx.scene.control.TreeView.setEditingItem(TreeView.java:715)
      at javafx.scene.control.TreeView.edit(TreeView.java:883)
      at com.sun.javafx.scene.control.behavior.TreeCellBehavior.edit(TreeCellBehavior.java:76)
      at com.sun.javafx.scene.control.behavior.TreeCellBehavior.handleClicks(TreeCellBehavior.java:91)
      at com.sun.javafx.scene.control.behavior.CellBehaviorBase.simpleSelect(CellBehaviorBase.java:259)
      at com.sun.javafx.scene.control.behavior.CellBehaviorBase.doSelect(CellBehaviorBase.java:220)
      at com.sun.javafx.scene.control.behavior.CellBehaviorBase.mouseReleased(CellBehaviorBase.java:159)
      at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
      at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
      at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
      at javafx.event.Event.fireEvent(Event.java:198)
      at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
      at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
      at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
      at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
      at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
      at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
      at com.sun.glass.ui.View.notifyMouse(View.java:937)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
      at java.lang.Thread.run(Thread.java:748)

      ---------- BEGIN SOURCE ----------
      public class TreeViewEventFilterBug extends Application {

          List<Employee> employees = Arrays.<Employee>asList(
                  new Employee("Ethan Williams", "Sales Department"),
                  new Employee("Emma Jones", "Sales Department"),
                  new Employee("Michael Brown", "Sales Department"),
                  new Employee("Anna Black", "Sales Department"),
                  new Employee("Rodger York", "Sales Department"),
                  new Employee("Susan Collins", "Sales Department"),
                  new Employee("Mike Graham", "IT Support"),
                  new Employee("Judy Mayer", "IT Support"),
                  new Employee("Gregory Smith", "IT Support"),
                  new Employee("Jacob Smith", "Accounts Department"),
                  new Employee("Isabella Johnson", "Accounts Department"));
          TreeItem<String> rootNode = new TreeItem<>("MyCompany Human Resources");

          public static void main(String[] args) {
              Application.launch(args);
          }

          @Override
          public void start(Stage stage) {
              rootNode.setExpanded(true);
              for (Employee employee : employees) {
                  TreeItem<String> empLeaf = new TreeItem<>(employee.getName());
                  boolean found = false;
                  for (TreeItem<String> depNode : rootNode.getChildren()) {
                      if (depNode.getValue().contentEquals(employee.getDepartment())) {
                          depNode.getChildren().add(empLeaf);
                          found = true;
                          break;
                      }
                  }
                  if (!found) {
                      TreeItem depNode = new TreeItem(employee.getDepartment());
                      rootNode.getChildren().add(depNode);
                      depNode.getChildren().add(empLeaf);
                  }
              }

              stage.setTitle("Double Click on a Leaf");
              VBox box = new VBox();
              final Scene scene = new Scene(box, 400, 300);
              scene.setFill(Color.LIGHTGRAY);

              TreeView<String> treeView = new TreeView<>(rootNode);
              treeView.setEditable(true);
              treeView.setCellFactory((TreeView<String> p) -> new TextFieldTreeCell());

              box.getChildren().addAll(treeView);
              stage.setScene(scene);

              stage.show();

              stage.addEventFilter(EventType.ROOT, e -> { }); //bug come from this added event filter, comment this line and the bug disappear

          }

          public static class Employee {

              private final SimpleStringProperty name;
              private final SimpleStringProperty department;

              private Employee(String name, String department) {
                  this.name = new SimpleStringProperty(name);
                  this.department = new SimpleStringProperty(department);
              }

              public String getName() {
                  return name.get();
              }

              public void setName(String fName) {
                  name.set(fName);
              }

              public String getDepartment() {
                  return department.get();
              }

              public void setDepartment(String fName) {
                  department.set(fName);
              }
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              pmangal Priyanka Mangal (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: