changeset 6126:ec8f70da59a4

RT-35338: [TableView] NullPointerException when clicking empty area in TableView
author jgiles
date Thu, 16 Jan 2014 11:12:04 +1300
parents c2f14b01f0d0
children 73ca8a2e497d
files modules/controls/src/main/java/javafx/scene/control/TableView.java modules/controls/src/main/java/javafx/scene/control/TreeTableView.java modules/controls/src/test/java/javafx/scene/control/TableViewMouseInputTest.java modules/controls/src/test/java/javafx/scene/control/TreeTableViewMouseInputTest.java
diffstat 4 files changed, 39 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/javafx/scene/control/TableView.java	Wed Jan 15 14:04:48 2014 -0800
+++ b/modules/controls/src/main/java/javafx/scene/control/TableView.java	Thu Jan 16 11:12:04 2014 +1300
@@ -2142,6 +2142,8 @@
         }
 
         @Override public void clearAndSelect(int row, TableColumn<S,?> column) {
+            if (row < 0 || row >= getItemCount()) return;
+
             // RT-33558 if this method has been called with a given row/column
             // intersection, and that row/column intersection is the only
             // selection currently, then this method becomes a no-op.
--- a/modules/controls/src/main/java/javafx/scene/control/TreeTableView.java	Wed Jan 15 14:04:48 2014 -0800
+++ b/modules/controls/src/main/java/javafx/scene/control/TreeTableView.java	Thu Jan 16 11:12:04 2014 +1300
@@ -2338,6 +2338,8 @@
         }
 
         @Override public void clearAndSelect(int row, TableColumnBase<TreeItem<S>,?> column) {
+            if (row < 0 || row >= getItemCount()) return;
+
             // RT-33558 if this method has been called with a given row/column
             // intersection, and that row/column intersection is the only
             // selection currently, then this method becomes a no-op.
--- a/modules/controls/src/test/java/javafx/scene/control/TableViewMouseInputTest.java	Wed Jan 15 14:04:48 2014 -0800
+++ b/modules/controls/src/test/java/javafx/scene/control/TableViewMouseInputTest.java	Thu Jan 16 11:12:04 2014 +1300
@@ -464,4 +464,21 @@
         assertFalse(sm.isSelected(4));
         assertTrue(fm.isFocused(4));
     }
+
+    @Test public void test_rt_35338() {
+        tableView.getItems().setAll("Row 0");
+        tableView.getColumns().setAll(col0);
+
+        col0.setWidth(20);
+        tableView.setMinWidth(1000);
+        tableView.setMinWidth(1000);
+
+        TableRow row = (TableRow) VirtualFlowTestUtils.getCell(tableView, 4);
+        assertNotNull(row);
+        assertNull(row.getItem());
+        assertEquals(4, row.getIndex());
+
+        MouseEventFirer mouse = new MouseEventFirer(row);
+        mouse.fireMousePressAndRelease(1, 100, 10);
+    }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/TreeTableViewMouseInputTest.java	Wed Jan 15 14:04:48 2014 -0800
+++ b/modules/controls/src/test/java/javafx/scene/control/TreeTableViewMouseInputTest.java	Thu Jan 16 11:12:04 2014 +1300
@@ -614,4 +614,22 @@
         assertFalse(sm.isSelected(4));
         assertTrue(fm.isFocused(4));
     }
+
+    @Test public void test_rt_35338() {
+        root.getChildren().clear();
+        tableView.setRoot(root);
+        tableView.getColumns().setAll(col0);
+
+        col0.setWidth(20);
+        tableView.setMinWidth(1000);
+        tableView.setMinWidth(1000);
+
+        TreeTableRow row = (TreeTableRow) VirtualFlowTestUtils.getCell(tableView, 4);
+        assertNotNull(row);
+        assertNull(row.getItem());
+        assertEquals(4, row.getIndex());
+
+        MouseEventFirer mouse = new MouseEventFirer(row);
+        mouse.fireMousePressAndRelease(1, 100, 10);
+    }
 }