Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8267392: ENTER key press on editable TableView throws NPE #505

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -891,15 +891,20 @@ protected void activate(KeyEvent e) {
if (fm == null) return;

TablePositionBase<TC> cell = getFocusedCell();
sm.select(cell.getRow(), cell.getTableColumn());
TC tableColumn = cell.getTableColumn();
sm.select(cell.getRow(), tableColumn);
setAnchor(cell);

if (tableColumn == null) {
return;
}

// check if we are editable
boolean isEditable = isControlEditable() && cell.getTableColumn().isEditable();
boolean isEditable = isControlEditable() && tableColumn.isEditable();

// edit this row also
if (isEditable && cell.getRow() >= 0) {
editCell(cell.getRow(), cell.getTableColumn());
editCell(cell.getRow(), tableColumn);
e.consume();
}
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -63,6 +63,7 @@
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -191,6 +192,19 @@ private boolean isAnchor(int row, int col) {
assertTrue(sm.isSelected(1));
}

@Test
public void testEnterOnFocusedRowDoesNotThrowNP() {
Maran23 marked this conversation as resolved.
Show resolved Hide resolved
tableView.setEditable(true);

assertNull(tableView.getSelectionModel().getSelectedItem());
assertEquals(0, tableView.getFocusModel().getFocusedCell().getRow());

// Fire an ENTER event on the focused row. This should not throw a NP!
keyboard.doKeyPress(KeyCode.ENTER);

assertNotNull(tableView.getSelectionModel().getSelectedItem());
}

@Test public void testDownArrowDoesNotChangeSelectionWhenAtLastIndex() {
int endIndex = tableView.getItems().size() - 1;
sm.clearAndSelect(endIndex);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -62,6 +62,7 @@
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -242,6 +243,19 @@ private int getItemCount() {
* Tests for row-based single selection
**************************************************************************/

@Test
public void testEnterOnFocusedRowDoesNotThrowNP() {
tableView.setEditable(true);

assertNull(tableView.getSelectionModel().getSelectedItem());
assertEquals(0, tableView.getFocusModel().getFocusedCell().getRow());

// Fire an ENTER event on the focused row. This should not throw a NP!
keyboard.doKeyPress(KeyCode.ENTER);

assertNotNull(tableView.getSelectionModel().getSelectedItem());
}

@Test public void testDownArrowChangesSelection() {
sm.clearAndSelect(0);
keyboard.doDownArrowPress();
Expand Down