JDK-8204074 : TreeTableView's selectedItems may contain null elements instead of being empty
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 8,9,10,openjfx11
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: x86_64
  • Submitted: 2018-05-29
  • Updated: 2020-06-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
Run the attached code and you'll notice that treeTable.getSelectionModel().getSelectedItems() array contains 3 null elements when there is noting selected in the TreeTableView.


---------- BEGIN SOURCE ----------
package com.test;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class TreeTable extends Application {
	public static void main(String[] pArgs) {launch(pArgs);}

	public void start(Stage pStage) {
		final BorderPane pane = new BorderPane();
		final Scene scene = new Scene(pane);
		pStage.setScene(scene);

		TreeTableView<String> treeTable = new TreeTableView<>();
		TreeTableColumn<String,String> col = new TreeTableColumn<>("Column 1");
		col.setCellValueFactory(features -> features.getValue().valueProperty());
		treeTable.getColumns().add(col);
		col = new TreeTableColumn<>("Column 2");
		col.setCellValueFactory(features -> features.getValue().valueProperty());
		treeTable.getColumns().add(col);

		treeTable.setRoot(new TreeItem<>("root"));
		treeTable.setShowRoot(false);
		treeTable.getRoot().getChildren().add(new TreeItem<>("a"));
		treeTable.getRoot().getChildren().add(new TreeItem<>("b"));
		treeTable.getRoot().getChildren().add(new TreeItem<>("c"));

		pane.setCenter(treeTable);
		pStage.show();

		treeTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
		treeTable.getSelectionModel().selectAll();

		treeTable.getRoot().getChildren().clear();

		System.out.println("Elements: ");
		for (TreeItem<String> item: treeTable.getSelectionModel().getSelectedItems()) {
			if (item == null) {
				System.out.println("null item");
			} else {
				System.out.println(item.getValue());
			}
		}
		System.out.println();		
	}
}

---------- END SOURCE ----------


Comments
Issue is reproducible. After calling 'treeTable.getRoot().getChildren().clear()', 'treeTable.getSelectionModel().getSelectedItems()' is not EMPTY. Windows 10, 64-bit JDK results: ------------------------- 8b132 : Fail [3 root items] 8u20-b20 : Fail [3 root items] 8u171-b11 ; Fail [3 null items] 9.0.4 : Fail [1 null item] 10+46 : Fail [1 null item] 11-ea+13 : Fail [1 null item] -----------------------------
30-05-2018