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

ClassCastException when pressing F2 or Enter on editable TreeTableView

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u66, 9
    • Fix Version/s: 9
    • Component/s: javafx
    • Labels:
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_66"
      Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      I create an editable TreeTableView and I add an event handler of type TreeTableView.EditEvent.ANY to parent of this tree table. After displaying this view, pressing F2 causes a ClassCastException to be thrown. The same is when pressing ENTER or SPACE.

      The same problem is with TreeView (as mentioned in http://stackoverflow.com/questions/17889561/simple-javafx-eventhandler-throws-exception).

      When event handler is not added, then works as expected.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Run attached code sample
      2. When application window shows, press F2

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      TreeTable cell should switch to edit mode
      ACTUAL -
      Exception is thrown and cell doesn't switch to edit mode



      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "JavaFX Application Thread" java.lang.ClassCastException: javafx.scene.layout.BorderPane cannot be cast to javafx.scene.control.TreeTableView
      at javafx.scene.control.TreeTableView$EditEvent.getSource(TreeTableView.java:2127)
      at javafx.scene.control.TreeTableView$EditEvent.getSource(TreeTableView.java:2097)
      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.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:49)
      at javafx.event.Event.fireEvent(Event.java:198)
      at javafx.scene.Node.fireEvent(Node.java:8411)
      at javafx.scene.control.TreeTableRow.startEdit(TreeTableRow.java:312)
      at javafx.scene.control.TreeTableRow.updateEditing(TreeTableRow.java:460)
      at javafx.scene.control.TreeTableRow.lambda$new$133(TreeTableRow.java:103)
      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.ReadOnlyObjectWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyObjectWrapper.java:176)
      at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:142)
      at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
      at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
      at javafx.scene.control.TreeTableView.setEditingCell(TreeTableView.java:1122)
      at javafx.scene.control.TreeTableView.edit(TreeTableView.java:1712)
      at com.sun.javafx.scene.control.behavior.TreeTableViewBehavior.editCell(TreeTableViewBehavior.java:179)
      at com.sun.javafx.scene.control.behavior.TableViewBehaviorBase.activate(TableViewBehaviorBase.java:934)
      at com.sun.javafx.scene.control.behavior.TableViewBehaviorBase.callAction(TableViewBehaviorBase.java:179)
      at com.sun.javafx.scene.control.behavior.TreeTableViewBehavior.callAction(TreeTableViewBehavior.java:92)
      at com.sun.javafx.scene.control.behavior.BehaviorBase.callActionForEvent(BehaviorBase.java:218)
      at com.sun.javafx.scene.control.behavior.TableViewBehaviorBase.callActionForEvent(TableViewBehaviorBase.java:208)
      at com.sun.javafx.scene.control.behavior.BehaviorBase.lambda$new$74(BehaviorBase.java:135)
      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.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$KeyHandler.process(Scene.java:3964)
      at javafx.scene.Scene$KeyHandler.access$1800(Scene.java:3910)
      at javafx.scene.Scene.impl_processKeyEvent(Scene.java:2040)
      at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2501)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:197)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:147)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$353(GlassViewEventHandler.java:228)
      at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:227)
      at com.sun.glass.ui.View.handleKeyEvent(View.java:546)
      at com.sun.glass.ui.View.notifyKey(View.java:966)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
      at java.lang.Thread.run(Thread.java:745)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.beans.property.StringProperty;
      import javafx.scene.Scene;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeTableColumn;
      import javafx.scene.control.TreeTableView;
      import javafx.scene.control.TreeTableView.EditEvent;
      import javafx.scene.control.cell.TextFieldTreeTableCell;
      import javafx.scene.control.cell.TreeItemPropertyValueFactory;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      public class TableTest extends Application {

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

          @Override
          public void start( Stage primaryStage ) throws Exception {
              BorderPane root = new BorderPane();
              Scene scene = new Scene( root, 400, 400 );
              primaryStage.setScene( scene );

              TreeItem< Person > rootItem = new TreeItem<>( new Person( "John" ) );
              TreeTableView< Person > treeTable = new TreeTableView<>( rootItem );

              TreeTableColumn< Person, String > treeNameColumn = new TreeTableColumn<>( "name" );
              treeNameColumn.setCellValueFactory( new TreeItemPropertyValueFactory<>( "name" ) );
              treeNameColumn.setCellFactory( TextFieldTreeTableCell.forTreeTableColumn() );
              treeNameColumn.setEditable( true );
              treeTable.getColumns().add( treeNameColumn );

              treeTable.setEditable( true );
              root.setCenter( treeTable );

              // !!! This is important to reproduce the bug
              root.addEventHandler( EditEvent.ANY, e -> {} );

              primaryStage.show();
          }

          public static class Person {

              private final SimpleStringProperty name;

              public Person( String name ) {
                  this.name = new SimpleStringProperty( name );
              }

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

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

              public StringProperty nameProperty() {
                  return name;
              }
          }
      }
      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jgiles Jonathan Giles
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: