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

IndexOutOfBoundsException in TreeView / SelectionModel

    Details

      Description

      If you have a TreeView with a selected TreeItem, and then remove all TreeItems, I get the following exception:

      java.lang.IndexOutOfBoundsException: bitIndex < 0: -1
      at java.util.BitSet.clear(BitSet.java:532)
      at javafx.scene.control.MultipleSelectionModelBase.clearSelection(Unknown Source)
      at javafx.scene.control.TreeView$TreeViewBitSetSelectionModel$2.handle(Unknown Source)
      at javafx.scene.control.TreeView$TreeViewBitSetSelectionModel$2.handle(Unknown Source)
      at com.sun.javafx.scene.control.WeakEventHandler.handle(Unknown Source)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
      at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
      at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
      at javafx.event.Event.fireEvent(Unknown Source)
      at javafx.scene.control.TreeItem.fireEvent(Unknown Source)
      at javafx.scene.control.TreeItem.updateChildren(Unknown Source)
      at javafx.scene.control.TreeItem.access$100(Unknown Source)
      at javafx.scene.control.TreeItem$2.onChanged(Unknown Source)
      at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(Unknown Source)
      at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(Unknown Source)
      at com.sun.javafx.collections.ObservableListWrapper.callObservers(Unknown Source)
      at com.sun.javafx.collections.ObservableListWrapper.remove(Unknown Source)



      To reproduce, run the code. Then select an item, and remove all items via the menu. The exception isn't always thrown, but in most cases. (I don't get the error, when I select the sub item of the first tree item "TreeItem 1").
      It probably affects other controls, which use the selection model, too.



      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.*;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;


      public class TestApp3 extends Application {
          public static void main(String[] args) throws Exception {
              launch(args);
          }

          public void start(final Stage stage) throws Exception {

              VBox root = new VBox();

              final TreeItem<String> rootNode = new TreeItem<String>();
              TreeView<String> treeView = new TreeView<String>(rootNode);
              treeView.setShowRoot(false);

              for (int i = 0; i < 10; i++) {
                  TreeItem<String> item = new TreeItem<String>();
                  item.setValue("TreeItem" + i);

                  TreeItem<String> subItem = new TreeItem<String>();
                  subItem.setValue("SubItem");
                  item.getChildren().add(subItem);
                  item.setExpanded(true);
                  rootNode.getChildren().add(item);
              }

              MenuBar menuBar = new MenuBar();
              Menu menu = new Menu("Menu");
              MenuItem menuitem = new MenuItem("Remove all items");
              menu.getItems().add(menuitem);

              menuitem.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent actionEvent) {
                      for (int i = 9; i >= 0; i--)
                      rootNode.getChildren().remove(i);
                  }
              });

              menuBar.getMenus().add(menu);

              root.getChildren().addAll(menuBar, treeView);

              Scene scene = new Scene(root, 500, 500);
              stage.setScene(scene);
              stage.show();
          }
      }

        Attachments

          Activity

            People

            • Assignee:
              jgiles Jonathan Giles
              Reporter:
              cschudtjfx Christian Schudt (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: